java - Swing GridBagLayout - Alignment issue -


i have jpanel jlabel, jtextfield , jpanel jlabel in it.

    createdomainpanel = new jpanel(new gridbaglayout());     gridbagconstraints gbc = new gridbagconstraints();     //createdomainpanel.setsize(600, 300);     gbc.fill=gridbagconstraints.horizontal;       gbc.gridx=0;     gbc.gridy=0;     createdomainpanel.add(new jlabel("enter name of domain"), gbc);      gbc.gridx=0;     gbc.gridy=1;             createdomainpanel.add(domainname, gbc);      jpanel result = new jpanel(new flowlayout());     result.add(successmessage);     gbc.anchor=gridbagconstraints.last_line_start;     gbc.gridx=0;     gbc.gridy=2;     createdomainpanel.add(result); 

the last jlabel result prints success message after operation.

 public void actionperformed(actionevent e) {         simpledbconnect dbc = new simpledbconnect();         string name = "";         if (e.getsource()==domainname){             name=e.getactioncommand();             boolean success = dbc.adddomain(name);             if (success){                 successmessage.settext("domain "+ name + " added successfully");             }         }      }    

however problem when success response, success message instead of being @ bottom appears @ right of first jlabel. i'm pretty new swings. can me out?

enter image description here

you forget pass constraints when adding results panel

createdomainpanel.add(result, gbc); 

Popular posts from this blog