Opening a static form/jFrame on clicking on button
I have two JFrames. The first one is defined as public firstJframe
and the second one is defined as 开发者_StackOverflow社区public static final jFrame
. I want to open the second JFrame on clicking a button on the first JFrame. How can I do this?
.setVisible
does not work for this. I really don't know how to proceed with this.
Try calling revalidate() for the object you want to update(in your case the second frame).
Example:
JButton myButton = new JButton("Open new window");
JFrame newFrame = new JFrame("New Window");
myButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
newFrame.pack();
newFrame.setVisible(true);
newFrame.revalidate();
}
});
Update
If that does not work, try calling this:
newFrame.invalidate();
newFrame.validate();
I propose:
under the button
type
:
this.dispose
new public static final jFrame.setvisible(true);
精彩评论