Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
586 views
in Technique[技术] by (71.8m points)

java - JTabbedPane JLabel, JTextField

Right, I have a JTabbedPane that has a JPanel that contains a JLabel and a JTextField.

my code

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);

textfield declaration :

    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);

private void createPanels() {
    controlPanel = new JPanel();
    controlPanel.setSize(650,500);
}
 private void fillPanels() {
    controlPanel.add(channelLabel);
    controlPanel.add(channelTxtFld);

}

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

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 ?

thank you :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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, 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...