tabs
  • 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
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
tabs
  • 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(); } }
e.mccormick
  • 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
tabs
  • 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

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

e.mccormick
  • 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); } ```
tabs
  • 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|
e.mccormick
  • e.mccormick
Start from this and see what you can do: ``` import java.awt.Color; import java.awt.GridLayout; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.border.Border; public class FramePanelExample extends JFrame{ private JFrame mainFrame; private JLabel Label1; private JLabel Label2; private JPanel Panel1; private JPanel Panel2; public FramePanelExample(){ buildGUI(); } private void buildGUI(){ mainFrame = new JFrame("I am a frame!"); mainFrame.setSize(600,650); mainFrame.setLocation(400,50); mainFrame.setLayout(new GridLayout(2,1)); mainFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent windowEvent){ System.exit(0); } }); Border blackLine = BorderFactory.createLineBorder(Color.black); Panel1 = new JPanel(); Panel1.setBorder(BorderFactory.createTitledBorder(blackLine, "Panel One")); Panel2 = new JPanel(); Panel2.setBorder(BorderFactory.createTitledBorder(blackLine, "Panel Two")); Label1 = new JLabel("This is label one"); Label2 = new JLabel("This is label two"); Panel1.add(Label1); Panel2.add(Label2); mainFrame.add(Panel1); mainFrame.add(Panel2); mainFrame.setVisible(true); } public static void main(String[] args){ new FramePanelExample(); } } ```
e.mccormick
  • e.mccormick
Oh, and you can move things around to make it more modular. That may or may not make a difference. For a simple program that is for learning, modularity is not a big deal. As you grow as a programmer you usually want things to be more modular, commented, etc. So your names should reflect what is happening so that nobody has to guess what the purpose of each part is. Let me modify mine a bit to show this. ``` import java.awt.Color; import java.awt.GridLayout; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.border.Border; public class FramePanelExample extends JFrame{ private JFrame mainFrame; private JLabel inputMessage; // Placeholder for input private JLabel outputMessage; // Placeholder for output private JPanel inputPanel; // Panel to hold all input controls private JPanel outputPanel; // Panel to display all output private Border blackLine = BorderFactory.createLineBorder(Color.black); public FramePanelExample(){ buildFrame(); } // end FramePanelExample() private void buildFrame(){ // sets up the main frame of the program mainFrame = new JFrame("Input to Output Program"); mainFrame.setSize(600,650); mainFrame.setLocation(400,50); mainFrame.setLayout(new GridLayout(2,1)); mainFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent windowEvent){ System.exit(0); } }); } // end buildFrame() private void addPannels(){ // adds panels to the program inputPanel = new JPanel(); inputPanel.setBorder(BorderFactory.createTitledBorder(blackLine, "Input")); outputPanel = new JPanel(); outputPanel.setBorder(BorderFactory.createTitledBorder(blackLine, "Output")); inputMessage = new JLabel("Input will go here."); outputMessage = new JLabel("Output will show here."); inputPanel.add(inputMessage); outputPanel.add(outputMessage); mainFrame.add(inputPanel); mainFrame.add(outputPanel); } // end addPannels() private void makeVisible(){ mainFrame.setVisible(true); } public static void main(String[] args){ FramePanelExample framePanelExample = new FramePanelExample(); framePanelExample.addPannels(); framePanelExample.makeVisible(); } } ```

Looking for something else?

Not the answer you are looking for? Search for more explanations.