Я пытаюсь реализовать графический интерфейс в Java Swing; но я застрял на размер кнопки, которую я пытаюсь сделать меньше. Я пытался использовать setSize
, setPrefferedSize
и setmaximumSize
, но ничего не получалось. Есть идеи?
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<String, Order> OrdersList;
private HashMap<String, Product> ProductsList;
public WorkStationGUI(HashMap<String, Order> orders, HashMap<String, Product> 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) {
}
}