Why is my JFrame not showing?
I'm pretty sure I've done it this way before, but for some reason, the JFrame won't show up when I开发者_开发知识库 run it.
JLabel originalString = new JLabel("Original String: "
+ str.getMutator());
JLabel currentString = new JLabel("Current String: "
+ str.getMutator());
JLabel finalString = new JLabel("Final String: " + str.getTarget());
JPanel panel = new JPanel();
panel.add(originalString);
panel.add(currentString);
panel.add(finalString);
JFrame frame = new JFrame("Mutating String!");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
Try to set size or check with the preferred size of your components probably because you call pack().
frame.setSize(x, y);
Your problem must be somewhere else (is the method called does it throw an exception ?) because your code works (I commented the str calls) :
http://img217.imageshack.us/img217/902/screenvlg.png
import javax.swing.*;
public class Test{
public static void main(String... args){
JLabel originalString = new JLabel("Original String: " /*+ str.getMutator()*/);
JLabel currentString = new JLabel("Current String: "/* + str.getMutator()*/);
JLabel finalString = new JLabel("Final String: " /* + str.getTarget()*/);
JPanel panel = new JPanel();
panel.add(originalString);
panel.add(currentString);
panel.add(finalString);
JFrame frame = new JFrame("Mutating String!");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
}
精彩评论