java - Align JTextFields in GridBagLayout -


i looking solution align 2 jtextfields different sizes in gridbaglayout. instead of maintaining original size of jtextfield prefer both end in same column.

    gridbagconstraints gbc = new gridbagconstraints();     gbc.anchor = gridbagconstraints.first_line_start;     gbc.ipady =  10;      jlabel lb1 = new jlabel("user: ");     jlabel lb2 = new jlabel("name: ");     jlabel lb3 = new jlabel("first ");     jlabel namelb = new jlabel("last ");     jtextfield tf1 = new jtextfield(20);     jtextfield tf2 = new jtextfield(20);     jtextfield nametf = new jtextfield(20);     gbc.gridx = 0;     gbc.gridy = 0;     add(lb1,gbc);      gbc.gridx = 0;     gbc.gridy = 1;     add(lb2,gbc);      gbc.gridx = 1;     gbc.gridy = 0;     gbc.gridwidth = 2;     add(tf1,gbc);      gbc.gridx = 1;     gbc.gridy = 1;     gbc.gridwidth = 1;     add(lb3,gbc);      gbc.gridx = 2;     gbc.gridy = 1;     gbc.gridwidth = 1;     add(tf2,gbc);      gbc.gridx = 1;     gbc.gridy = 2;     gbc.gridwidth = 1;     add(namelb,gbc);      gbc.gridx = 2;     gbc.gridy = 2;     gbc.gridwidth = 1;     add(nametf,gbc); 

i assume tf1 causing issue. if text field not extending end add fill constraint. try

gbc.fill =  gridbagconstraints.horizontal; pane.add(tf1, gbc); 

if not working can post full code or more description problem?


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -