我已经在这里很长一段时间了,但我似乎无法得到它。我试图生成一个JPanel,它具有上面的JTextArea和下面的两个JLabel,但是我的JLabel最终在我的JTextArea的左侧,而我不能让其他的出现。JPanels:一个带有JTextArea,另一个带有JLabel
这里是我的代码(对不起显示stuff-只是填料真的):
public JPanel contentPane() {
JPanel something = new JPanel();
String information = "Please";
info = new JTextArea(information, 4, 30);
info.setEditable(false);
info.setLineWrap(true);
info.setWrapStyleWord(true);
JPanel one = new JPanel(new BorderLayout());
one.setBackground(Color.WHITE);
one.setLocation(10, 10);
one.setSize(50, 50);
one.add(info, BorderLayout.CENTER);
something.add(one, BorderLayout.NORTH);
JPanel two = new JPanel(new BorderLayout());
two.setBackground(null);
two.setLocation(220, 10);
two.setSize(50, 50);
two.add(new JLabel("Please work"), BorderLayout.EAST);
two.add(new JLabel("Oh gosh, please"), BorderLayout.WEST);
something.add(two, BorderLayout.SOUTH);
something.setOpaque(true);
return something;
}
public static void GUI() {
JFrame frame = new JFrame("You Guessed It!");
DisplayStudent panel = new DisplayStudent();
frame.setContentPane(panel.contentPane());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 150);
frame.setVisible(true);
}
请和谢谢你的人谁需要时间来帮助。
您正在使用哪个版本的JDK? – masterX244
@ masterX244 7.4我相信。 – Zanpo