Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
582 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...