java - Needing help to place swing components correctly -
in order pass college course, need code software java , swing api. have issues place components want :
i want place components in moodpanel: like this
which layout should use moodpanel , best way components in second draw ?
edit : i'm trying apply solution below, have problems : here
public moodpanel(){ super(); this.setbackground(new color(255, 255,0)); this.setlayout(new boxlayout(this,boxlayout.y_axis)); this.choicepanel = new jpanel(); this.choicepanel.setlayout(new gridbaglayout()); this.choicepanel.setbackground(new color(255, 0, 0)); gridbagconstraints c = new gridbagconstraints(); this.statpanel = new jpanel(); this.statpanel.setlayout(new borderlayout()); this.lidtweet= new jlabel(); c.fill = gridbagconstraints.horizontal; c.gridwidth=3; c.gridx=0; c.gridy=0; c.weightx=0.0; c.anchor =gridbagconstraints.first_line_start; this.choicepanel.add(this.lidtweet,c); this.moodgroup = new buttongroup(); this.jrbad = new jradiobutton("mauvais"); this.jrbad.setactioncommand("0"); this.jrbad.setvisible(false); c.fill = gridbagconstraints.horizontal; c.gridx=0; c.gridy=1; c.weightx=0.0; this.choicepanel.add(this.jrbad,c); this.jrneutral = new jradiobutton("neutre"); this.jrneutral.setactioncommand("2"); c.fill = gridbagconstraints.horizontal; c.weightx=1.0; c.insets = new insets(0,70, 0, 0); this.choicepanel.add(this.jrneutral,c); this.jrneutral.setvisible(false); this.jrgood = new jradiobutton("bon"); this.jrgood.setvisible(false); this.jrgood.setactioncommand("4"); c.fill = gridbagconstraints.horizontal; c.weightx=0.0; c.insets = new insets(0,0, 0, 0); this.choicepanel.add(this.jrgood,c); this.moodgroup.add(this.jrbad); this.moodgroup.add(this.jrneutral); this.moodgroup.add(this.jrgood); this.buttonpanel = new jpanel(); this.buttonpanel.setlayout(new flowlayout(flowlayout.center)); this.intializinglistener(); this.btnaddtolist = new jbutton("ajouter"); this.btnaddtolist.addactionlistener(okaction); this.mpclose= new jbutton("fermer"); this.mpclose.addactionlistener(cancelaction); this.buttonpanel.add(btnaddtolist); this.buttonpanel.add(mpclose); this.buttonpanel.setvisible(false); this.buttonpanel.setsize(new dimension(this.buttonpanel.getpreferredsize().width,this.btnaddtolist.getpreferredsize().height)); this.buttonpanel.setbackground(new color(60, 90, 60)); c.fill = gridbagconstraints.horizontal; c.gridx=0; c.gridy=1; c.weightx=0.0; c.gridwidth=3; this.choicepanel.add(buttonpanel,c); this.add(choicepanel,borderlayout.north); this.add(statpanel,borderlayout.south);
when comes designing layouts, need break down each section in needs , responsibilities, while whole layout using gridbaglayout
's, it's way on kill.
instead, can use series of compounding layouts, each adding previous layouts doing, example...
if @ main layout, see 2 main areas, more or less...
this screams borderlayout
(again gridbaglayout
work)
now, start focusing north
section
the question needs answered here is, 3 sections equal in height? if are, gridlayout
work, if not, i'd leaning towards gridbaglayout
the last 2 sections same...
you need answer question, elements going given same of horizontal space or not? if size equally, can use gridlayout
, if not, use either flowlayout
or gridbaglayout
depending on needs , desires.
try never @ "whole" ui , try , solve in 1 single step, times, want break down areas of functionality, allow separate areas of responsibility in code , generate self contained units of work can base classes on.
see laying out components within container more details.
Comments
Post a Comment