Not sure what you're looking for, but you can add JMenuBar
to JFrame
- JFrame.setJMenuBar(). Look at How to Use Menus tutorial for details.
Edit:
Below is an overly simplified example of undecorated frame with a menu, just to demo the idea.
You may want to turn to existing solutions - JIDE has ResizableFrame
for this purpose. It is part of open source JIDE-oss. Substance L&F has support for title bar customization (see What happened to the Substance LaF?). You can also very efficiently utilize ComponentMover
and ComponentResizer
classes by @camickr, see Resizing Components article for more details.
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class UndecoratedFrameDemo {
private static Point point = new Point();
public static void main(String[] args) {
final JFrame frame = new JFrame();
frame.setUndecorated(true);
frame.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
point.x = e.getX();
point.y = e.getY();
}
});
frame.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
Point p = frame.getLocation();
frame.setLocation(p.x + e.getX() - point.x,
p.y + e.getY() - point.y);
}
});
frame.setSize(300, 300);
frame.setLocation(200, 200);
frame.setLayout(new BorderLayout());
frame.getContentPane().add(new JLabel("Drag to move", JLabel.CENTER),
BorderLayout.CENTER);
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Menu");
menuBar.add(menu);
JMenuItem item = new JMenuItem("Exit");
item.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
menu.add(item);
frame.setJMenuBar(menuBar);
frame.setVisible(true);
}
}