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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:38:35+00:00 2026-05-27T14:38:35+00:00

I noticed very strange behavior of my program today. Basically I have JToolBar uder

  • 0

I noticed very strange behavior of my program today. Basically I have JToolBar uder which is JScrollPane with JTable. Both inside JPanel inside JFrame. Every container using MigLayout.

Now, if I start app, this is its default look: enter image description here

But, if I move JToolBar and clip it back to its original position, now it looks like this:enter image description here

Suddenly there are no borders. I would preffer if there werent any at all at first place, but changing look of GUI is not good feature at all… Please if you know what is wrong, help 🙂

CODE:

public class Gui extends JFrame {

private static final long serialVersionUID = 1L;
private JPanel mainPnl = null;
private JToolBar toolbar = null;
private Session session = null;

public Gui(Session session) {
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (UnsupportedLookAndFeelException e) {
    } catch (ClassNotFoundException e) {
    } catch (InstantiationException e) {
    } catch (IllegalAccessException e) {
    }

    this.session = session;

    setTitle("PRO2-Contact Manager v_0.1");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(800,420);
    setResizable(true);

    initMenu();
    initMainPnl();
    initToolbar();
    initTable();

    // KeyboardFocusManager manager =
    // KeyboardFocusManager.getCurrentKeyboardFocusManager();
    // manager.addKeyEventDispatcher(new MyDispatcher(aList));

    setLocationRelativeTo(null);
    setVisible(true);
}

private void initMenu() {
    JMenuBar menu = new JMenuBar();
    MenuListener ml = new MenuListener();

    JMenu file = new JMenu("File");
    file.setMnemonic(KeyEvent.VK_F);
    menu.add(file);

    JMenuItem exit = new JMenuItem("Exit");
    exit.setMnemonic(KeyEvent.VK_E);
    exit.addActionListener(ml);
    file.add(exit);

    JMenu help = new JMenu("Help");
    help.setMnemonic(KeyEvent.VK_H);
    menu.add(help);

    JMenuItem controls = new JMenuItem("Controls");
    controls.setMnemonic(KeyEvent.VK_C);
    controls.addActionListener(ml);
    help.add(controls);

    JMenuItem about = new JMenuItem("About");
    about.setMnemonic(KeyEvent.VK_A);
    about.addActionListener(ml);
    help.add(about);

    setJMenuBar(menu);
}

private void initMainPnl(){
    mainPnl = new JPanel(new MigLayout());

    add(mainPnl);
}

private void initToolbar() {
    toolbar = new JToolBar(JToolBar.HORIZONTAL);
    toolbar.add(new JButton());
    mainPnl.add(toolbar,"wrap");
}

private void initTable() {
    MyTable table = new MyTable(new MyTableModel(this));
    JScrollPane sp = new JScrollPane(table);
    sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    mainPnl.add(sp,"w 100%, h 100%");
}}
  • 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-27T14:38:35+00:00Added an answer on May 27, 2026 at 2:38 pm

    Technically, a JToolBar can be added to a container with any layout constraint. Automatic re-adding a floating toolBar to the container is supported only if for a BorderLayout. Instead of adding to the mainPanel, add it to the contentPane:

    private void initToolbar() {
        toolbar = new JToolBar(JToolBar.HORIZONTAL);
        toolbar.add(new JButton());
        add(toolbar, BorderLayout.NORTH);
    }
    

    BTW: your code doesn’t compile outside of your context – MyPanel, MyTableModel, MenuListener are local classes not available anywhere else plus it’s missing a main method. For better help sooner, consider to supply a SSCCE in future 🙂

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

Sidebar

Related Questions

While creating the sample, I noticed very strange behavior and due to which I
I've noticed some very strange behaviour today in Code Igniter. I have this locations
I am using FileWriter and I have noticed strange behavior. I buffer my collection
When compiling code which uses code contracts, I have a very strange error I
I have switched on the Codeigniter profile (very useful) and I have noticed that
I'm noticing strange behavior. I have merchant and order tables and doing two selects
I am seeing very, VERY strange behavior when I run certain reports: >> p
I have noticed that with Delphi 2009, I often get strange errors when compiling,
I'm debugging a program I wrote and noticed something strange. I set up an
While writing a Javascript inheritance function some time ago I noticed some very strange

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.