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 9182765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:38:18+00:00 2026-06-17T18:38:18+00:00

I am new to Java Swing.I want to design one JToolBar . The JToolBar

  • 0

I am new to Java Swing.I want to design one JToolBar. The JToolBar should be placed in center of JPanel. Is it possible?

javax.swing.JPanel pane = new javax.swing.JPanel(); 
BorderLayout border = new BorderLayout(); 
pane.setLayout(border); 
JToolBar toolBar = new JToolBar(); 
pane.add(toolBar,BorderLayout.CENTER); 
javax.swing.JButton button1 = new javax.swing.JButton("Click Me"); 
toolBar.add(button1);
  • 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-17T18:38:20+00:00Added an answer on June 17, 2026 at 6:38 pm

    Read about How to use ToolBars.

    The following code is taken straight from the doc.

    public ToolBarDemo() {
        super(new BorderLayout());
        ...
        JToolBar toolBar = new JToolBar("Still draggable");
        addButtons(toolBar);
        ...
        setPreferredSize(new Dimension(450, 130));
        add(toolBar, BorderLayout.PAGE_START);
        add(scrollPane, BorderLayout.CENTER);
    }
    

    See the usage of BorderLayout here. And do the necessary changes in your code.

    UPDATE:

    I have tried using your code which shows output like this. I have used addSeparator method with dimension. This is just a try to solve the problem. I am not sure whether this approach is the correct way.

    enter image description here

    public static void main(String[] args) {
        JFrame frame = new JFrame();
        JPanel panel = new JPanel(new BorderLayout()); 
        JToolBar toolBar = new JToolBar(); 
        panel.add(toolBar,BorderLayout.PAGE_START);
    
        toolBar.addSeparator(new Dimension(150, 0));
    
        JButton button1 = new JButton("Click Me"); 
        toolBar.add(button1);
        frame.setLayout(new BorderLayout());
        frame.add(panel, BorderLayout.CENTER);
        frame.setSize(new Dimension(400, 100));
        frame.setVisible(true);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Java Swing I want to develop an POS application which
I'm writing a new Java 6 Swing application and want to have a Show
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 in netbeans and java swing, but also confused. I put some JLabel's
I'm new to java.I'm creating a swing based UI. I've created 2 frames, each
I'm building a little app using Java and Swing in NetBeans. Using NetBeans design
I'm trying to build a new java swing component, I realise that I might
hi friends I am creating a software in java swing where i want to
Possible Duplicate: Java AWT/Swing: Get notified on change of position/size of my window Is

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.