any one who can help me with java swing... my panels are not appearing at the place I want them plzzz urgent help needed
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(); } }
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
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
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); } ```
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|
Join our real-time social learning platform and learn together with your friends!