I have developed a Swing Java Application with only one JFrame
with a JPanel
inside it.
When I run that in Eclipse it is displaying correctly, but when I try to export as a Runnable Jar or Export to NetBeans it doesn't display the inner JPanel
, just a empty JFrame
.
Running in Eclipse
Running in JVM or NetBeans:
Code
public LoadJPanel(){
Font_PalMap_rest = getCustomFont(ID_CODE_FONT_REST);
Font_PalMap_title = getCustomFont(ID_CODE_FONT_TITLE);
ImagePanel panel = new ImagePanel(new ImageIcon(Background_path).getImage());
btnAddAndroid = getButtonConfig(ID_CODE_BUTTON_ADD_ANDROID_DEVICE);
btnSendSMS = getButtonConfig(ID_CODE_BUTTON_SEND_SMS_AUTO);
btnOpenFolder = getButtonConfig(ID_CODE_BUTTON_OPEN_FOLDER);
JLabel label_lembretePalmas = getLabelConfig(ID_CODE_LABEL_TITLE);
JFrame frame = new JFrame("LembretePalmas");
textArea = getTextAreaConfig(ID_CODE_DISPLAYING_PROCESS_AREA);
scrollPane = getScrollPaneConfig(ID_CODE_DISPLAYING_PROCESS_AREA,textArea);
panel.add(btnAddAndroid);
panel.add(btnSendSMS);
panel.add(label_lembretePalmas);
panel.add(scrollPane);
panel.add(btnOpenFolder);
panel.setVisible(true);
frame.getContentPane().setLayout(new FlowLayout());
frame.getContentPane().add(panel, SwingConstants.CENTER);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setIconImage(new ImageIcon(Icon_path).getImage());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
setServer();
}
I solved the problem.
It works when I copy the image's folder in the same path that the JAR is located.
I added System.getProperty("user.dir"));
too at the beginning of the image's path.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.