JTabbedPane JLabel,JTextField [英] JTabbedPane JLabel, JTextField
问题描述
是的,我有一个JTabbedPane,它有一个包含JLabel和JTextField的JPanel。
Right, I have a JTabbedPane that has a JPanel that contains a JLabel and a JTextField.
我的代码
JTabbed Pane声明:
JTabbed Pane declaration :
this.tabPane = new JTabbedPane();
this.tabPane.setSize(750, 50);
this.tabPane.setLocation(10, 10);
tabPane.setSize(750,450);
tabPane.add("ControlPanel",controlPanel);
文本字段声明:
this.channelTxtFld = new JTextField("");
this.channelTxtFld.setFont(this.indentedFont);
this.channelTxtFld.setSize(200, 30);
this.channelTxtFld.setLocation(200, 10);
JLabel:
this.channelLabel = new JLabel(Channel name:);
this.channelLabel.setSize(150,30);
this.channelLabel.setLocation(10,10);
JLabel : this.channelLabel = new JLabel("Channel name : "); this.channelLabel.setSize(150, 30); this.channelLabel.setLocation(10,10);
private void createPanels() {
controlPanel = new JPanel();
controlPanel.setSize(650,500);
}
private void fillPanels() {
controlPanel.add(channelLabel);
controlPanel.add(channelTxtFld);
}
那么我的计划是,有一个标签式窗格有一个JPanel我在固定位置有一些标签,文本字段和按钮,但在这之后这是我的结果:
So what my plan is, was to have a tabbed pane that has a JPanel where I have some Labels, textfields and buttons on fixed positions, but after doing this this is my result:
http://i.stack.imgur.com/vXa68.png
我想要的是我有JLabel,旁边是一个完整的JTextfield,左边不是中间。
What I wanted was that I had the JLabel and next to it a full grown JTextfield on the left side not in the middle.
任何人都知道我的错误是什么?
Anyone any idea what my mistake is ?
谢谢:)
推荐答案
什么样的布局管理器是你使用controlPanel,你可能想要BorderLayout,将Label放在西方,TextField放在中心。
What kind of Layout Manager are you using for your controlPanel, you probably want BorderLayout, putting the Label in the West, and the TextField in the center.
BTW,设置各种组件的大小和位置没有意义,除非你使用Null布局,这不是一个好主意。所以我会删除所有这些东西,让布局管理器为你做。
BTW, setting the size and position of various components doesn't make sense unless you are using a Null Layout, which isn't a good idea. So i'd remove all that stuff and let the Layout Manager do it for you.
这篇关于JTabbedPane JLabel,JTextField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!