Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7569941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:17:33+00:00 2026-05-30T15:17:33+00:00

I am trying to implement a GUI in Java Swing; but I am stuck

  • 0

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 setSize, setPrefferedSize and setmaximumSize, but nothing worked. Any ideas?

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) {
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:17:34+00:00Added an answer on May 30, 2026 at 3:17 pm

    You are using GridLayout which will cause the component to take up all container space, relative to the grid. It’s not really the best choice for buttons. You might try using a FlowLayout, or GridBagLayout instead.

    Also, you are setting the layout manager AFTER you are setting the JButton on the panel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement Swing worker in my GUI. At the moment I have
I am trying to make a GUI in Java, using something along these lines:
I'm trying to restructure some specific GUI code in a Java project, let's call
I have a Java GUI project containing a JMenuBar and I just added a
Im trying to use the following code to eventually make a game. The code,
I am trying to implement ping using HttpGet but behavior is random. I am
I am trying to write a Qt GUI application which can communicate with an
I'm fairly new to GUI. I'm trying to make it so that depending on
Hi am new to java and have been trying to create a form for
I am trying to implement some sort of MVC in Java. Actually it's more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.