Not sure what you're looking for, but you can add a JMenuBar
to a JFrame
- JFrame.setJMenuBar () . See How to use the menu for details.
Edit:
Below is an oversimplified example of a disordered frame with a menu, just to showcase the idea.
You can refer to existing solutions - for this purpose JIDE has a ResizableFrame
. This is part of the open source JIDE-oss . The L & F agent supports header customization (see What happened to LaF? ). You can also very efficiently use the ComponentMover
and ComponentResizer
classes by @camickr, see Resizing components 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(px + e.getX() - point.x, py + 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); } }
source share