Hallo Forum,
ich will eine Oberfläche mit Textfeldern bauen. Der code für das Panel sieht so aus:
Nur leider Haben die JTextFields eine Breite von 0. http://www.java-forum.org/de/userfiles/user9476/2007-08-17_141734.png
Was mach ich da falsch?
Grüße Eric
ich will eine Oberfläche mit Textfeldern bauen. Der code für das Panel sieht so aus:
Code:
public class ServerPanel extends JPanel {
static private final Logger logger = Logger.getLogger(ServerPanel.class);
static private final int TEXT_COLUMNS = 20;
private Controller controller = null;
// Server A
private JTextField serverAUrl = new JTextField( TEXT_COLUMNS);
private JTextField serverAPort = new JTextField( TEXT_COLUMNS);
// Server B
private JTextField serverBUrl = new JTextField( TEXT_COLUMNS);
private JTextField serverBPort = new JTextField( TEXT_COLUMNS);
private JCheckBox echoBox = new JCheckBox();
private JButton connect = new JButton("connect");
/** */
public ServerPanel(Controller controller) {
super();
this.controller = controller;
this.init();
}
private void init(){
// layout
this.setLayout( new GridBagLayout() );
GridBagConstraints constrains = new GridBagConstraints();
// server A
constrains.gridx = 0;
constrains.gridy = 0;
JLabel serverALabel = new JLabel( "ServerA" );
this.add( serverALabel, constrains );
constrains.gridx = 1;
this.add( this.serverAUrl, constrains );
constrains.gridx = 2;
this.add( this.serverAPort, constrains );
// server B
constrains.gridx = 0;
constrains.gridy = 1;
JLabel serverBLabel = new JLabel( "ServerB" );
this.add( serverBLabel, constrains );
constrains.gridx = 1;
this.add( this.serverBUrl, constrains );
constrains.gridx = 2;
this.add( this.serverBPort, constrains );
// echo
constrains.gridx = 3;
this.add( this.echoBox, constrains );
constrains.gridx = 4;
this.add( new JLabel("echo"), constrains );
constrains.gridx = 5;
this.add( this.connect, constrains );
this.connect.addActionListener( this.controller );
}
}
Nur leider Haben die JTextFields eine Breite von 0. http://www.java-forum.org/de/userfiles/user9476/2007-08-17_141734.png
Was mach ich da falsch?
Grüße Eric