[英]JButton is not displayed in JFrame
if(compressedImageFilePath.exists()){
final String ie = Integer.toString(i);
JFrame mboxFrame1 = new JFrame("Optimized Image");
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
ImageIcon image1 = new ImageIcon(compressedImageFile);
JLabel reader1 = new JLabel(image1);
mboxFrame1.setContentPane(reader1);
controlPanel2 = new JPanel();
JButton saveButton = new JButton("SAVE");
saveButton.setVisible(true);
mboxFrame1.setSize(screenSize.width, screenSize.height-30);
mboxFrame1.setResizable(true);
mboxFrame1.setVisible(true);
mboxFrame1.add(headerLabel);
mboxFrame1.add(controlPanel2);
controlPanel2.add(saveButton);
mboxFrame1.add(controlPanel2, BorderLayout.WEST);
}
Here i am checking for a particular file. 在这里,我正在检查一个特定的文件。 If that file exists i am creating a new Jrame and adding the Save Button to it. 如果该文件存在,我将创建一个新的Jrame并向其中添加“保存”按钮。 But the save button is not getting displayed.Where am i going wrong? 但是保存按钮没有显示出来,我哪里出问题了?
Please add your panel to frame. 请添加您的面板到框架。 Hope that will solve the problem 希望能解决问题
You can try 你可以试试
mboxFrame1.getContentPane().add(reader1,BorderLayout.NORTH);
instead of 代替
mboxFrame1.setContentPane(reader1);
you don't add the JPanel you added the button to to the Jframe in any way. 您不以任何方式添加将按钮添加到Jframe的JPanel。 use a layout on your jframe and add the JPanel to the layout. 在jframe上使用布局,然后将JPanel添加到布局。 easy to use is BorderLayout
易于使用的BorderLayout
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.