Opening a static form / jFrame when a button is clicked

I have two JFrames. The first of them is defined as public firstJframe, and the second - public static final jFrame. I want to open a second JFrame when I click a button on the first JFrame. How can i do this?

.setVisiblefor this does not work. I really don't know how to do this.

+3
source share
2 answers

Try calling revalidate () on 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 this does not work, try calling:

newFrame.invalidate();
newFrame.validate();
0
source

I suggest: under button type:

this.dispose

new public static final jFrame.setvisible(true);
-1
source

Source: https://habr.com/ru/post/1795195/


All Articles