I'm using a custom class that extends JFrame, but sometimes it shows nothing. I never get any faults, so I'm curious if the is a java command that can help me print something. I looked around for other questions, but found nothing similar. Not really doing anything too crazy, but curious as to why this happens. I would like to correct the problem to avoid future problems.
Blank
GUI
public MemberPanel(int i) throws IOException {
Container contentPane = getContentPane();
GridLayout layout = new GridLayout(2, 1);
contentPane.setLayout(layout);
setVisible(true);
setLocation(0, 0);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(640, 170);
setResizable(false);
greenStatus = new JButton("Non-Critical");
yellowStatus = new JButton("Important");
redStatus = new JButton("Mission Critical");
greenStatus.setFont(fontTextOne);
yellowStatus.setFont(fontTextOne);
redStatus.setFont(fontTextOne);
greenStatus.addActionListener(this);
yellowStatus.addActionListener(this);
redStatus.addActionListener(this);
buttonPanel.add(greenStatus);
buttonPanel.add(yellowStatus);
buttonPanel.add(redStatus);
statusLabel = new JLabel("In 75 letters or less... What are you working on?");
statusLabel.setVerticalAlignment(JLabel.CENTER);
statusLabel.setHorizontalAlignment(JLabel.CENTER);
statusLabel.setFont(fontTextTwo);
textFieldPanel.add(statusLabel);
textFieldPanel.add(statusMessage);
contentPane.add(buttonPanel);
contentPane.add(textFieldPanel);
}
Method SummaryAdds a listener to the list that's notified each time a change to the data model occurs. Returns the value at the specified index. Returns the length of the list. Removes a listener from the list that's notified each time a change to the data model occurs.
“Look” refers to the appearance of GUI widgets and “feel” refers to the way the widgets behave. Sun's JRE provides the following L&Fs: CrossPlatformLookAndFeel: this is the “Java L&F” also known as “Metal” that looks the same on all platforms. It is part of the Java API (javax. swing.
You're adding a bunch of components after calling setVisible(true)
on the JFrame:
public MemberPanel(int i) throws IOException {
Container contentPane = getContentPane();
GridLayout layout = new GridLayout(2, 1);
contentPane.setLayout(layout);
setVisible(true); // ****** here
// .....
// only now do you add components...
contentPane.add(buttonPanel);
contentPane.add(textFieldPanel);
}
And so the components may or may not show depending on whether the GUI repaints or not (see what happens when you re-size the empty gui). Fix: call setVisible(true)
only after adding everything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With