Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A few suggestions:</p> <ol> <li>Don't set the JFrame's size, and in fact don't set any sizes.</li> <li>Call pack to all the components to set their own sizes.</li> <li>If you want the buttons bigger, consider changing the size of their fonts.</li> </ol> <p>e.g.,</p> <p><img src="https://i.stack.imgur.com/fLKZJ.png" alt="Calc2 GUI"></p> <pre><code>import java.awt.BorderLayout; import java.awt.Font; import java.awt.GridLayout; import javax.swing.*; public class Calc2 { public static final String[][] BUTTON_TEXTS = { {"7", "8", "9", "+"}, {"4", "5", "6", "-"}, {"1", "2", "3", "*"}, {"0", ".", "/", "="} }; public static final Font BTN_FONT = new Font(Font.SANS_SERIF, Font.BOLD, 24); private static void createAndShowGui() { JTextField field = new JTextField(10); field.setFont(BTN_FONT.deriveFont(Font.PLAIN)); JPanel btnPanel = new JPanel(new GridLayout(BUTTON_TEXTS.length, BUTTON_TEXTS[0].length)); for (int i = 0; i &lt; BUTTON_TEXTS.length; i++) { for (int j = 0; j &lt; BUTTON_TEXTS[i].length; j++) { JButton btn = new JButton(BUTTON_TEXTS[i][j]); btn.setFont(BTN_FONT); btnPanel.add(btn); } } JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(field, BorderLayout.PAGE_START); mainPanel.add(btnPanel, BorderLayout.CENTER); JFrame frame = new JFrame("Calc2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGui(); } }); } } </code></pre>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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