I am trying to get some text to display to the menu bar at the top of my application (the empty white space at the end of the row). I could add it as a JMenu with no JMenuItems, I suppose, but I'd really prefer to have it non-clickable. Does anyone know where to start looking to accomplish this? If it isn't possible, is there any way to add a JMenu to the end of the row?
Thanks
Does anyone know where to start looking to accomplish this?
Yes, you would control the positioning with an appropriate LayoutManager
, and as @MadProgrammer suggested, probably just add a JLabel
to your JMenuBar
.
Here is a minimal working example. It might not be exactly what you're looking for, but it does show you where to start looking.
import java.awt.*;
import javax.swing.*;
public class Example {
public static void main(String args[]) {
JFrame frame = new JFrame();
JMenuBar menubar = new JMenuBar();
JLabel label = new JLabel("Hello World");
menubar.setLayout(new BorderLayout());
menubar.add(label, BorderLayout.EAST);
frame.setLayout(new BorderLayout());
frame.add(menubar, BorderLayout.PAGE_START);
frame.setMinimumSize(new Dimension(200, 100));
frame.setVisible(true);
}
}