为什么我的 JLabels 和 JTextFields 没有出现在 JPanel 中?
我有一个 JDialog,里面有一个使用 FlowLayout 的 JPanel
现在我已经使用 Netbeans GUI 生成器创建了 3 个标签和文本字段,并且我想使用代码添加另外 2 个文本字段
我已经调整了面板的大小这样,当我添加新标签和具有首选大小的文本字段时,新的标签集 - 文本字段将位于
JDialog 中某处的
JLabel cores = new JLabel("Cores");
cores.setPreferredSize(new Dimension(70,15));
first = new JTextField();
first.setPreferredSize(new Dimension(140,20));
JLabel power = new JLabel("Power");
power.setPreferredSize(new Dimension(70,15));
second = new JTextField();
second.setPreferredSize(new Dimension(140,20));
panel2.add(cores);panel2.add(first);panel2.add(power);panel2.add(second);
前一组标签下,当我编译程序时,标签不会显示也没有文本字段
当我向下并单击时,我得到以下结果
http://img684.imageshack.us/img684/13/unledlpy.png
如果我输入内容,文本字段会出现
http://img5.imageshack.us/img5/6796/unledhig.png
但标签没有出现,我认为我没有对属性进行任何更改,任何帮助将不胜感激谢谢
I have a JDialog and inside it I have a JPanel that uses FlowLayout
now I've created 3 labels and text fields using the Netbeans GUI Builder, and I want to add 2 more text fields using code
I've adjusted the size of the panel so that when I add a new label and a textfield with a preferred size the new set of label - textfield will be under the previous set
somewhere in the JDialog I do something like this
JLabel cores = new JLabel("Cores");
cores.setPreferredSize(new Dimension(70,15));
first = new JTextField();
first.setPreferredSize(new Dimension(140,20));
JLabel power = new JLabel("Power");
power.setPreferredSize(new Dimension(70,15));
second = new JTextField();
second.setPreferredSize(new Dimension(140,20));
panel2.add(cores);panel2.add(first);panel2.add(power);panel2.add(second);
when I compile the program, the labels don't show up and neither do the textfields
when I go down and click I have the following result
http://img684.imageshack.us/img684/13/unledlpy.png
if I type something, the text field appears
http://img5.imageshack.us/img5/6796/unledhig.png
the labels don't appear though, I don't think I made any changes to the properties, any help would be appreciated thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建对象时定义列数。
像这样
Define the no of columns while creating object.
like this