Note that there are some explanatory texts on larger screens.

plurals
  1. POSet button size smaller in Java Swing
    primarykey
    data
    text
    <p>I am trying to implement a GUI in Java Swing; but I am stuck on the button size, which I am trying to make smaller. I have tried to use <code>setSize</code>, <code>setPrefferedSize</code> and <code>setmaximumSize</code>, but nothing worked. Any ideas?</p> <pre><code>import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.HashMap; import javax.swing.JButton; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.*; import javax.swing.border.Border; public class WorkStationGUI extends JFrame implements ActionListener { JButton Worker1Process1; JButton Worker1Process2; JButton StopWorking; // JScrollPane scrollList; JTextArea OrderList; JTextArea ProductList; JTextField orders; JTextField products; JTextField Worker1; JTextField Worker2; private HashMap&lt;String, Order&gt; OrdersList; private HashMap&lt;String, Product&gt; ProductsList; public WorkStationGUI(HashMap&lt;String, Order&gt; orders, HashMap&lt;String, Product&gt; Products) { this.OrdersList = orders; this.ProductsList = Products; setTitle("Work Station"); setupEastandWest(); setupSouthPanel(); pack(); setVisible(true); } private JLabel createOneLabel(String s, Color c) { Font f = new Font(Font.SANS_SERIF, Font.BOLD, 18); JLabel label = new JLabel(s, JLabel.CENTER); label.setFont(f); label.setBackground(c); label.setOpaque(true); return label; } private void setupEastandWest() { // search panel contains label, text field and button JPanel Panel = new JPanel(); Worker1Process1 = new JButton("Worker 1"); Worker1Process1.setPreferredSize(new Dimension(10, 10)); Panel.add(Worker1Process1); Worker1 = new JTextField(20); Worker1Process1.setPreferredSize(new Dimension(90, 90)); Worker1.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); Worker1.setEditable(false); Panel.setLayout(new GridLayout(2, 1)); Panel.add(Worker1); JPanel Panel2 = new JPanel(); Worker1Process2 = new JButton("Worker 2"); Panel2.add(Worker1Process2); Worker2 = new JTextField(20); Worker2.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); Worker2.setEditable(false); Panel2.setLayout(new GridLayout(2, 1)); Panel2.add(Worker2); Panel.setLayout(new GridLayout(2, 2)); this.add(Panel, BorderLayout.EAST); this.add(Panel2, BorderLayout.WEST); // this.add(Panel2, BorderLayout.SOUTH); } private void setupSouthPanel() { JPanel Panel = new JPanel(); orders = new JTextField(1); orders.setBackground(Color.LIGHT_GRAY); Panel.add(orders); JPanel Panel2 = new JPanel(); products = new JTextField(1); Panel.add(products); products.setBackground(Color.LIGHT_GRAY); Panel.setLayout(new GridLayout(2, 2)); this.add(Panel, BorderLayout.CENTER); this.add(Panel2, BorderLayout.SOUTH); } public void actionPerformed(ActionEvent e) { } } </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.
 

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