Paintrick Paintrick - 1 year ago 58
Java Question

How can I create a bar in the bottom of a Java app, like a status bar?

I am in the process of creating a Java app and would like to have a bar
on the bottom of the app, in which I display a text bar and a status (progress) bar.

Only I can't seem to find the control in NetBeans neither do I know the code to create in manually.

Thank you so much for helping!

Answer Source

Create a JFrame or JPanel with a BorderLayout, give it something like a BevelBorder or line border so it is seperated off from the rest of the content and then add the status panel at BorderLayout.SOUTH.

JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.setSize(200, 200);

// create the status bar panel and shove it down the bottom of the frame
JPanel statusPanel = new JPanel();
statusPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
frame.add(statusPanel, BorderLayout.SOUTH);
statusPanel.setPreferredSize(new Dimension(frame.getWidth(), 16));
statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS));
JLabel statusLabel = new JLabel("status");


Here is the result of the above status bar code on my machine:

enter image description here