java - How to make window all of (1) no title (2) moveable (3) only menu bar [how to listen mouse events over menu bar] -
I only have the menu bar and the main window to run.
It would be better with some window frames, but with drag, it seems that this is impossible in Java. So, I tried to listen straight to the mouse events, but could not hear them:
package tests.javax.swing; Import java.awt.Dimension; Import java.awt.Menu; Import java.awt.MenuBar; Import java.awt.MenuItem; Import java.awt.Point; Import java.awt.Toolkit; Import java.awt.event.ActionEvent; Import java.awt.event.ActionListener; Import java.awt.event.MouseAdapter; Import java.awt.event.MouseEvent; Import java.awt.event.MouseMotionAdapter; Import javax.swing.JFrame; Import javax.swing.SwingUtilities; Import org.slf4j.Logger; Import org.slf4j.LoggerFactory; Public Square Try_NarrowWindow {Private Static Last Logar Log = LoggerFactory.getLogger (Try_NarrowWindow.class); public static void (String [] args) {SwingUtilities.invokeLater (new Runnable () {@SuppressWarnings ({ "serial"}) @Override public void run () {JFrame frame = new JFrame () {Point mouseDownCompCoords; {setDefaultCloseOperation ( EXIT_ON_CLOSE); setResizable (false); SetUndecorated (right); SetMenuBar (new menu bar () {{(new menus ( "add file") {{add (new MenuItem ( "Open ...")); (adding new MenuItem ( "off")); AddSeparator (); (add new MenuItem ( "Exit") {{AddActionListener (new ActionListener () {@Override public void actionPerformed (ActionEvent e) {dispose ();}});}} );}}); (New menu ("Edit") {{(New menu item ("copy Add "new" (new menu item ("cut")); add (new menu system ("paste");}});}}); addMouseListener (new mouseAdapter () {public zero mouseReleased (MouseEvent e) {log .info ( "mouseReleased ({})", e); MouseDownCompCoords = null;} public void mousePressed (MouseEvent e) {log.info ( "mousePressed ({})", e); Mausdauncompakords = Ikgetpoint (); }}); addMouseMotionListener (New MouseMotionAdapter () {public void mouseDragged (MouseEvent e) {log.info ( "mouseDragged ({})", e); Point currCoords = e.getLocationOnScreen (); setLocation (currCoords.x - mouseDownCompCoords.x, currCoords .y - mouseDownCompCoords.y);}}};}}; frame.setLocation (0,0); frame.pack (); frame.setSize (new dimension ((int) Toolkit.getDefaultToolkit () getScreenSize () getWidth ( ) * 2/3, frame.getHeight ()) ..); frame.setVisible (true);}}); }}
check out
Assume that you have There are references to frames and menu bars; ComponentMover
can provide this functionality from a line of class code:
component-specific cm = new component head (frame, menu bar) ;
ComponentMover
The class is a general purpose class move to pull any component, either a component on the desktop or a component on the panel.
Comments
Post a Comment