So I have 3 JFrames. JFrame 1 (aka opts) is for inputting some variables. On OK, it creates JFrame 2 (aka view, a graphical viewing Frame). In the constructor, JFrame 3 (aka manager, for cycling through the graphical views) is created instantly.
I want them to be Windows-alike decorated with JFrame.setDefaultLookAndFeelDecorated(true) (from now on referred to as “it”).
A few differtent cases:
- When I don’t set it at all, all JFrames are Windows decorated.
- When I put it in the “opts” or “manager” constructor, run the project, and click the OK button, all JFrames are Windows-alike decorated.
- However, when I put it in the “view” constructor, only “opts” and “view” are Windows decorated, but “manager” is Java decorated.
- But when I put it in a class which does nothing more than read some data from a file, and make some objects out of it, only “opts” is Windows decorated.
How exactly does it work? I want to know why it happens as it happens.
Edit: I can’t reproduct case 4, but still, some things happen that I don’t understand. Try commenting out some of the “it”s. It’ll give some strange results.
package test;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Frame1 extends JFrame {
public Frame1() {
JFrame.setDefaultLookAndFeelDecorated(true);
Frame1.setOptions(this);
JButton b1 = new JButton("hi");
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
makeFrame2(2);
}
});
this.add(b1);
}
public void makeFrame2(int x) {
this.dispose();
new Frame2(x);
}
public static void setOptions(JFrame f) {
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(250, 250);
f.setEnabled(true);
f.setVisible(true);
}
public static void main(String[] args) {
new Frame1();
}
}
package test;
import javax.swing.JFrame;
public class Frame3 extends JFrame {
Frame2 link;
SomeClass sc;
public Frame3(Frame2 link) {
JFrame.setDefaultLookAndFeelDecorated(true);
Frame1.setOptions(this);
this.link = link;
sc = new SomeClass(25);
}
}
package test;
import javax.swing.JFrame;
public class SomeClass {
int x;
public SomeClass(int x) {
JFrame.setDefaultLookAndFeelDecorated(true);
this.x = x;
}
}
package test;
import javax.swing.JFrame;
public class Frame2 extends JFrame {
public Frame2(int x) {
JFrame.setDefaultLookAndFeelDecorated(true);
Frame1.setOptions(this);
new Frame3(this);
}
}
According to the oracle java documentation,
setDefaultLookAndFeelDecoratedchanges the parameter for all newly created JFrames, all existing JFrames are unchanged.JFrame Documentation