Java Swing GridBagLayout -
i've been learning java swing using gridbaglayout.
i have main jframe , add main jpanel, add subsequent jpanels/components main jpanel.
but add it positions center of main panel (including while resize), not desired result.
just small snippet on core code:
getcontentpane().setlayout(new gridbaglayout()); jpanel panel = new jpanel(new gridbaglayout()); getcontentpane().add(panel); gridbagconstraints gbc = new gridbagconstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.anchor = gridbagconstraints.northwest; jtextfield namefield = new jtextfield(10); panel.add(namefield, gbc) any feedback appreciated, thanks.
in future, post sscce when have problem. small "snippet" of code doesn't help.
read section swing tutorial on how use gridbaglayout. part on "weightx/weighty" explain why happens.
Comments
Post a Comment