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

  • Home
  • SEARCH
  • 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 8127945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:42:50+00:00 2026-06-06T07:42:50+00:00

I am new to Java Swing I want to develop an POS application which

  • 0

I am new to Java Swing I want to develop an POS application which is like this image:
enter image description here

To develop this application I am using Eclipse, I have created JPanel which is shown by numbers e.g(1, 2) in image. At no 3 I have added JscrollPan which contain JPanel, now I want to do here when I click a button from panel no 2 that should add new buttons in panel no 3 dynamically and at that time I want to show only three buttons at each line and scroll should be activate only vertically when needed. But I am not able to do that, because when I write scrollPanel.setPreferredSize(new Dimension(2, 3)); vertical scroll cannot work. My Code is here:

public class WelcomeUI extends JFrame {
    private JPanel contentPane;
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    WelcomeUI frame = new WelcomeUI();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
    public WelcomeUI() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(Toolkit.getDefaultToolkit().getScreenSize());
        setUndecorated(true);       
        contentPane = new JPanel();
        contentPane.setBackground(Color.LIGHT_GRAY);
        contentPane.setBorder(new EmptyBorder(0, 0, 0, 0));
        contentPane.setLayout(new BorderLayout(0, 0));
        setContentPane(contentPane);        
        header = new JPanel();
        header.setForeground(Color.BLUE);
        FlowLayout fl_header = (FlowLayout) header.getLayout();
        fl_header.setAlignment(FlowLayout.RIGHT);
        fl_header.setVgap(40);
        fl_header.setHgap(0);
        header.setBackground(Color.BLUE);
        contentPane.add(header, BorderLayout.NORTH);

        footer = new JPanel();
        FlowLayout flowLayout = (FlowLayout) footer.getLayout();
        flowLayout.setVgap(10);
        footer.setBackground(Color.BLUE);
        contentPane.add(footer, BorderLayout.SOUTH);

        panel_2 = new JPanel();
        panel_2.setBackground(Color.BLUE);
        contentPane.add(panel_2, BorderLayout.WEST);

        JButton btnSelectRestaurant = new JButton("Select Restaurant");
        btnSelectRestaurant.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                createDynamicButton(e);
            }
        });     
        JButton btnNewButton = new JButton("Select Steward");       
        JButton btnNewButton_1 = new JButton("Select Table");       
        JButton btnNewButton_2 = new JButton("Misc keys");
        GroupLayout gl_panel_2 = new GroupLayout(panel_2);
        gl_panel_2.setHorizontalGroup(
            gl_panel_2.createParallelGroup(Alignment.LEADING)
                .addGroup(gl_panel_2.createSequentialGroup()
                    .addGap(19)
                    .addGroup(gl_panel_2.createParallelGroup(Alignment.LEADING)
                        .addComponent(btnNewButton, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
                        .addComponent(btnSelectRestaurant, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnNewButton_1, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
                        .addComponent(btnNewButton_2, Alignment.TRAILING, 0, 0, Short.MAX_VALUE))
                    .addContainerGap())
        );
        gl_panel_2.setVerticalGroup(
            gl_panel_2.createParallelGroup(Alignment.LEADING)
                .addGroup(gl_panel_2.createSequentialGroup()
                    .addGap(26)
                    .addComponent(btnSelectRestaurant, GroupLayout.PREFERRED_SIZE, 43, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(ComponentPlacement.UNRELATED)
                    .addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 47, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(ComponentPlacement.UNRELATED)
                    .addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(ComponentPlacement.UNRELATED)
                    .addComponent(btnNewButton_2, GroupLayout.PREFERRED_SIZE, 41, GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(438, Short.MAX_VALUE))
        );
        gl_panel_2.setAutoCreateContainerGaps(true);
        gl_panel_2.setAutoCreateGaps(true);
        panel_2.setLayout(gl_panel_2);

        panel_3 = new JPanel();
        FlowLayout flowLayout_2 = (FlowLayout) panel_3.getLayout();
        flowLayout_2.setHgap(250);
        contentPane.add(panel_3, BorderLayout.EAST);

        scrollPane = new JScrollPane();     
        contentPane.add(scrollPane, BorderLayout.CENTER);       
        scrollPanel = new JPanel();     
        scrollPanel.setPreferredSize(new Dimension(2, 3));
        scrollPane.setViewportView(scrollPanel);        
    }
    protected void createDynamicButton(ActionEvent e) {     
        JButton dynButton = new JButton("My Button");
        dynButton.setPreferredSize(new Dimension(300, 200));        
        scrollPanel.add(dynButton);         
        scrollPanel.validate();
        scrollPanel.revalidate();       
    }   
    private JPanel header;
    private JPanel footer;
    private JPanel panel_2;
    private JPanel panel_3;
    private JPanel scrollPanel;
    private JScrollPane scrollPane;
}

So, please tell me where I am doing wrong. Thanks in advance.

  • 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-06-06T07:42:52+00:00Added an answer on June 6, 2026 at 7:42 am

    Focusing on panel 3, consider the following:

    1. Give the panel a GridLayout(0, 3), which specifies an arbitrary number rows in three columns.
    2. Implement the Scrollable interface, and let getPreferredScrollableViewportSize() return a a Dimension that is a multiple of the button height.
    3. As each button is added, give it a suitable Action.
    4. When adding a button, revalidate() the panel and repaint() it.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a new Java 6 Swing application and want to have a Show
I am new to the whole Java Swing/AWT dialogs (which explains how amateurish this
I have created a login page using java swing. and i created jar for
I want to implement a java awt/swing application but i am new to awt/swing.
I am developing desktop GUI application using java swing. And I want to show
I have a Java Swing application that i want to create a nice component
I am new to java Swing and I need a tool to develop attractive
I'm new to Java Swing applications and I'd like to port an old WindowsForm
I'm new to java.I'm creating a swing based UI. I've created 2 frames, each
I want to make a java swing application from where i can generated xml

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.