Ask your own question, for FREE!
Computer Science 14 Online
OpenStudy (tabs):

any one who can help me with java swing... my panels are not appearing at the place I want them plzzz urgent help needed

OpenStudy (tabs):

package mytest; import javax.swing.BorderFactory; import javax.swing.GroupLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class Testframe extends JFrame { private JPanel jp; private JPanel jp2; private JLabel jb; private JTextField jf; public Testframe() { //frame super ("Location box"); setSize(600,650); setLocation(400,50); //panel jp=new JPanel(); jp.setBorder(BorderFactory.createTitledBorder("NUMBER ADDITION")); jp.setForeground(new java.awt.Color(204, 204, 255)); javax.swing.GroupLayout jpLayout = new GroupLayout(jp); jp.setLayout(jpLayout); setVisible(true); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub new Testframe(); } }

OpenStudy (e.mccormick):

1) A code quotre system would make this a lot easier... copy paste does not work well without one on OS. 2) What exactly is wrong with how they get placed? 3) I do not see any code to tell the GroupLayout how you want things grouped. https://docs.oracle.com/javase/tutorial/uiswing/layout/group.html

OpenStudy (tabs):

thnx for your reply.. actually in this case it doesn't matter which layout I use. my panel never appears. and if I apply border layout then it comes but anything I want to add in a panel say textfield never comes into the panel... plz help me through this

OpenStudy (e.mccormick):

See what happens if you comment out the adding of the text field here: ``` public TestFrame() { //frame super ("Location box"); setSize(600,650); setLocation(400,50); //panel jp=new JPanel(); jp.setBorder(BorderFactory.createTitledBorder("NUMBER ADDITION")); jp.setForeground(new java.awt.Color(204, 204, 255)); javax.swing.GroupLayout jpLayout = new GroupLayout(jp); jp.setLayout(jpLayout); jb = new JLabel("Hello"); add(jb); final JTextField jf = new JTextField(6); add(jf); setVisible(true); } ```

OpenStudy (tabs):

it brings jlabel if I comment out txt field... that's what happening things overwrite each other no panel is appearing no titled border either... can u help me make a code having two small panels having separate labels and textfields in a common frame.. plzzzz|dw:1434372890465:dw|

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!