java - trying to align JcheckBox in a GridBagLayout -



java - trying to align JcheckBox in a GridBagLayout -

i'm working gridbaglayout , can't figure why jcheckbox don't align. i've tried set alignement jcheckbox parameter(i.e checkbox.setalignementx(left_alignement)). did'nt worked.

i first tried using borderlayout, turned out worst

what i'm trying acheive this

i want threee main categories(physique, psychologique , social) set on finish left, , want sub-categories set bit offset. way you'll know it's sub-categorie(according lines i've drawn).

there uis 3 jpanel, 1 each category. not original code reproduce problem have.

public class window extends jframe { private jbutton button = new jbutton("generer"); private jcheckbox physique = new jcheckbox("traits physiques"); private jcheckbox psychologic = new jcheckbox("traits psychologiques"); private jcheckbox mass = new jcheckbox("masse"); private jcheckbox quality = new jcheckbox("qualité"); private jtextarea text = new jtextarea(""); private jscrollpane scroller = new jscrollpane(text); private jpanel panel = new jpanel(); public window() { setlayout(new borderlayout()); settitle("personnage"); setsize(500, 350); setresizable(false); setdefaultcloseoperation(jframe.dispose_on_close); setlocationrelativeto(null); text.seteditable(false); arrange(); getcontentpane().add(panel, borderlayout.west); getcontentpane().add(scroller, borderlayout.center); getcontentpane().add(button, borderlayout.south); setvisible(true); } /** * arrange layout */ private void arrange() { jpanel phpanel = new jpanel(); jpanel pspanel = new jpanel(); gridbagconstraints gbcpanel, gbcph, gbcps; gbcpanel = gbcph = gbcps = new gridbagconstraints(); panel.setlayout(new gridbaglayout()); gbcpanel.gridx = 0; gbcpanel.gridy = 0; gbcpanel.gridheight = 1; gbcpanel.gridwidth = 1; panel.add(phpanel, gbcpanel); gbcpanel.gridy = 1; panel.add(pspanel, gbcpanel); //--------------------------- gbcph.gridx = 0; gbcph.gridy = 0; gbcph.gridheight = 1; gbcph.gridwidth = 2; phpanel.add(physique, gbcph); gbcph.gridx = 1; gbcph.gridy = 1; gbcph.gridwidth = 1; phpanel.add(mass, gbcph); //-------------------------- gbcps.gridx = 0; gbcps.gridy = 0; gbcps.gridheight = 1; gbcps.gridwidth = 2; pspanel.add(psychologic, gbcps); gbcps.gridx = 1; gbcps.gridy = 1; gbcps.gridwidth = 1; pspanel.add(quality, gbcps); //------------------------ }

}

i want main category(i.e physique , psychologic) align totally left , sub category(i.e mass , quality) bit offset. can't that, don't know how, i've read multiple tutorial etc...

the original code

honestly, setalignmentx isn't going much your, sethorizontalalignment improve choice, having said that, there other things can gridbagconstraints

to start with, utilize anchor , weightx properties...

phyconstraint.anchor = gridbagconstraints.west; phyconstraint.weightx = 1;

the anchor determine position within given cell component want align to, defaults center. weightx property describes amount of space given to, based on remaining space left on after layout has been calculated, in case, we're asking remaining space.

next, can utilize insets properties determine amount of internal spacing or margin cell have, impact position component when it's laid out...

phyconstraint.insets = new insets(0, 20, 0, 0);

finally, optionconstraint, can utilize fill property, determine how component size depending on amount of available space within there cell, in case, you'll want component expand fill available space, example...

optionconstraint.weightx = 1; optionconstraint.fill = gridbagconstraints.horizontal;

have @ how utilize gridbaglayout more details.

i'd consider having @ how utilize trees, might save trouble...

java swing layout-manager gridbaglayout jcheckbox

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -