Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set the size of a gridlayout jpanel
    primarykey
    data
    text
    <p>I'm trying to set the size of a gridlayout jpanel. Here is the code:</p> <pre><code>JFrame myFrame = new JFrame(); myFrame.setLayout(new FlowLayout()); myFrame.setLocation(400, 100); myFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JLabel jlMins = new JLabel("Number of minutes for tutoring session (should be a positive decimal number): 0.0"); JLabel jlEarnings = new JLabel("Earnings in dollars and cents received (should be positive decimal number): 0.0"); jtfMins = new JTextField(20); jtfEarnings = new JTextField(20); JPanel jpMins = new JPanel(new BorderLayout()); JPanel jpEarnings = new JPanel(new BorderLayout()); jpMins.setPreferredSize(new Dimension(300,50)); jpEarnings.setPreferredSize(new Dimension(300,50)); jpMins.add(jlMins,BorderLayout.NORTH); jpMins.add(jtfMins,BorderLayout.CENTER); jpEarnings.add(jlEarnings,BorderLayout.NORTH); jpEarnings.add(jtfEarnings,BorderLayout.CENTER); JButton jbQuit = new JButton("Quit"); JButton jbEnter = new JButton("Enter"); JButton jbReport = new JButton("Run Report"); jbQuit.setActionCommand("quit"); jbEnter.setActionCommand("enter"); jbReport.setActionCommand("report"); jbQuit.addActionListener(this); jbEnter.addActionListener(this); jbReport.addActionListener(this); JPanel jpButtons = new JPanel(new GridLayout(4,1,0,20)); jpButtons.setSize(new Dimension(50,150)); jpButtons.add(jbEnter); jpButtons.add(jbReport); jpButtons.add(jbQuit); JPanel jpNorth = new JPanel(new BorderLayout()); jpNorth.add(jpMins,BorderLayout.NORTH); jpNorth.add(jpEarnings,BorderLayout.CENTER); jpNorth.add(jpButtons,BorderLayout.SOUTH); jtaReports = new JTextArea(); jtaReports.setColumns(40); jtaReports.setRows(10); jtaReports.setLineWrap(true); JScrollPane jspReports = new JScrollPane(jtaReports); jspReports.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); JPanel jpSouth = new JPanel(); jpSouth.setPreferredSize(new Dimension(350,200)); jpSouth.add(jspReports); JPanel jpMain = new JPanel(new BorderLayout()); jpMain.add(jpNorth,BorderLayout.NORTH); jpMain.add(jpSouth,BorderLayout.SOUTH); jpMain.setPreferredSize(new Dimension(500,500)); myFrame.setContentPane(jpMain); myFrame.pack(); myFrame.setVisible(true); </code></pre> <p>The panel name is jpButtons. Of the above code I'm talking mainly about this section:</p> <pre><code> JButton jbQuit = new JButton("Quit"); JButton jbEnter = new JButton("Enter"); JButton jbReport = new JButton("Run Report"); jbQuit.setActionCommand("quit"); jbEnter.setActionCommand("enter"); jbReport.setActionCommand("report"); jbQuit.addActionListener(this); jbEnter.addActionListener(this); jbReport.addActionListener(this); JPanel jpButtons = new JPanel(new GridLayout(4,1,0,20)); jpButtons.setSize(new Dimension(50,150)); jpButtons.add(jbEnter); jpButtons.add(jbReport); jpButtons.add(jbQuit); </code></pre> <p>How exactly does setSize, and setPreferredSize work or how to get them to work properly on jpanel, components, etc.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload