Search Results

Search found 12 results on 1 pages for 'jpopupmenu'.

Page 1/1 | 1 

  • Why isn't componentHidden called for my JPopupMenu?

    - by heycam
    I want to be notified when my JPopupMenu is hidden — whether because an item was selected, the menu was dismissed, or setVisible(false) was called on it. Here is my test code: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class A extends ComponentAdapter implements Runnable, ActionListener { private JButton b; public static void main(String[] args) { EventQueue.invokeLater(new A()); } public void run() { JFrame f = new JFrame("Test"); b = new JButton("Click me"); b.addActionListener(this); f.add(b); f.pack(); f.setVisible(true); } public void actionPerformed(ActionEvent e) { JPopupMenu pm = new JPopupMenu(); pm.addComponentListener(this); pm.add("Popup..."); pm.add("...menu!"); pm.show(b, 10, 10); } public void componentShown(ComponentEvent e) { System.out.println("componentShown"); } public void componentHidden(ComponentEvent e) { System.out.println("componentHidden"); } } Regardless of how I interact with the menu, neither of the two ComponentListener methods are being called. Why is that? Is there different/better/correct way of finding out when my JPopupMenu is hidden? Thanks, Cameron

    Read the article

  • Problem with JPopupMenu in a JTree

    - by Alex
    Hi guys I have this issue. In a custom JTree I implemented a JPopupMenu to display different JMenuItem according to the node selected using a MouseListener. The JPopupMenu is shown when the mouse right button is clicked. The problem is that if I don’t choose an Item from the PopupMenu but instead I select another node in the tree, either with right or left buttons, this event is never caught by the tree MouseListener Could anyone point me in the right direction to solve this? In case an example is available I’ll appreciate it. Thanks.

    Read the article

  • Resizing JPopupMenu and avoiding a "flicker" issue

    - by Avrom
    Hi, I am trying to implement a search results popup list similar to the style found here: http://www.inquisitorx.com/ (I'm not trying to implement a Google search, I'm just using this as a rough example of the style I'm working on.) In any event, I am implementing this by using a JList contained within a JPopupMenu which is popped up underneath a JTextField. When a user enters search terms, the list changes to reflect different matching results. I then call pack on the JPopupMenu to resize it. This works, however, it creates a slight flicker effect since it is actually hiding the popup and showing a popup. (See the private method getPopup in JPopupMenu where it explicitly does this.) Is there any way to just get it to just resize itself (aside from using a JWindow)?

    Read the article

  • Showing/hiding a JPopupMenu from a JButton; FocusListener not working?

    - by M. Joanis
    Hi everyone, I needed a JButton with an attached dropdown style menu. So I took a JPopupMenu and attached it to the JButton in the way you can see in the code below. What it needs to do is this: show the popup when clicked hide it if clicked a second time hide it if an item is selected in the popup hide it if the user clicks somewhere else in the screen These 4 things work, but because of the boolean flag I'm using, if the user clicks somewhere else or selects an item, I have to click twice on the button before it shows up again. That's why I tried to add a FocusListener (which is absolutely not responding) to fix that and set the flag false in these cases. Here are the listeners: (It's in a class extending JButton, so the second listener is on the JButton.) // Show popup on left click. menu.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { System.out.println("LOST FOCUS"); isShowingPopup = false; } @Override public void focusGained(FocusEvent e) { System.out.println("GAINED FOCUS"); } }); addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("isShowingPopup: " + isShowingPopup); if (isShowingPopup) { isShowingPopup = false; } else { Component c = (Component) e.getSource(); menu.show(c, -1, c.getHeight()); isShowingPopup = true; } } }); I've been fighting with this for way too long now. If someone can give me a clue about what's wrong with this, it would be great! Thanks!

    Read the article

  • (Java) JPopupMenu won't close if I click outside of it

    - by Danny King
    Hi all, I have created a Java Swing app that has no visible main window but which is controlled through its tray icon by right-clicking. I am using a JPopupMenu for this, but when I click outside of the popup menu (e.g. on another application's window or the desktop) the JPopupMenu does not disappear which is not the expected behaviour. Originally I was using a popupMenu which did work as expected but this did not allow me to have icons in the menu. How can I get it to close when I click elsewhere, as expected? Thanks!

    Read the article

  • JPopupMenu returning a null?

    - by Zenzen
    Ok so I'm working on an Eclipse plugin based on the JGraph example. The problem is I can't really get the "save" method to work, here's how the program works in short: - I have a DiagramEditor class with an init() method, where I create a GraphEditor object and call the createFrame() methord of that object. - GraphEditor extends the BasicGraphEditor (which extends JPanel), the createFrame() method returns a JFrame and has a line "frame.setJMenuBar(menuBar)" - the "menuBar" is an object variable, which is initialized in the BasicGraphEditor. Till here everything is cool, the problem is with the action listener which is supposed to save a file. To get the graph I need to get the GraphEditor component, so I do a Component component = (Component) e.getSource() whitch is the ActionEvent passed to that action listener and at that stage is the JMenuItem "save", then I get the parent which is the JPopupMenu, then I want to get that JPopupMenu's parent which should be the GraphEdiotor, but instead I get a null. Any idea why? Here's some source code: DiagramEditor.java: @Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { setSite(site); setInput(input); this.diagram = ((DiagramEditorInput)input).getDiagram(); setPartName(this.diagram.getName()); gEditor = new GraphEditor(); gEditor.createFrame().setVisible(true); } BasicGraphEditor.java: public JFrame createFrame() { JFrame frame = new JFrame(); frame.getContentPane().add(this); frame.setJMenuBar(menuBar); //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(870, 640); return frame; } In the constructor: menuBar = new JMenuBar(); menu = new JMenu("File"); menu.setMnemonic(KeyEvent.VK_F); menuBar.add(menu); JMenuItem openMenuItem = new JMenuItem("Open", KeyEvent.VK_O); // ADD FILE OPENING //openMenuItem.addActionListener(menuListener); menu.add(openMenuItem); JMenuItem saveMenuItem = new JMenuItem("Save", new ImageIcon("/images/save.gif")); saveMenuItem.setMnemonic(KeyEvent.VK_S); saveMenuItem.addActionListener( new SaveAction(false) ); menu.add(saveMenuItem); // menu.add(new SaveAction(false)); JMenuItem saveMenuItemAs = new JMenuItem("SaveAs", new ImageIcon("/images/saveas.gif")); //saveMenuItemAs.setMnemonic(KeyEvent.VK_S); saveMenuItemAs.addActionListener( new SaveAction(true) ); menu.add(saveMenuItemAs); //menu.add(new SaveAction(true)); JMenuItem closeMenuItem = new JMenuItem("Close", KeyEvent.VK_C); closeMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } } ); menu.add(closeMenuItem);

    Read the article

  • JPopupMenu getParent() returning a null?

    - by Zenzen
    Ok so I'm working on an Eclipse plugin based on the JGraph example. The problem is I can't really get the "save" method to work, here's how the program works in short: - I have a DiagramEditor class with an init() method, where I create a GraphEditor object and call the createFrame() methord of that object. - GraphEditor extends the BasicGraphEditor (which extends JPanel), the createFrame() method returns a JFrame and has a line "frame.setJMenuBar(menuBar)" - the "menuBar" is an object variable, which is initialized in the BasicGraphEditor. Till here everything is cool, the problem is with the action listener which is supposed to save a file. To get the graph I need to get the GraphEditor component, so I do a Component component = (Component) e.getSource() whitch is the ActionEvent passed to that action listener and at that stage is the JMenuItem "save", then I get the parent which is the JPopupMenu, then I want to get that JPopupMenu's parent which should be the GraphEdiotor, but instead I get a null. Any idea why? Here's some source code: DiagramEditor.java: @Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { setSite(site); setInput(input); this.diagram = ((DiagramEditorInput)input).getDiagram(); setPartName(this.diagram.getName()); gEditor = new GraphEditor(); gEditor.createFrame().setVisible(true); } BasicGraphEditor.java: public JFrame createFrame() { JFrame frame = new JFrame(); frame.getContentPane().add(this); frame.setJMenuBar(menuBar); //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(870, 640); return frame; } In the constructor: menuBar = new JMenuBar(); menu = new JMenu("File"); menu.setMnemonic(KeyEvent.VK_F); menuBar.add(menu); JMenuItem openMenuItem = new JMenuItem("Open", KeyEvent.VK_O); // ADD FILE OPENING //openMenuItem.addActionListener(menuListener); menu.add(openMenuItem); JMenuItem saveMenuItem = new JMenuItem("Save", new ImageIcon("/images/save.gif")); saveMenuItem.setMnemonic(KeyEvent.VK_S); saveMenuItem.addActionListener( new SaveAction(false) ); menu.add(saveMenuItem); // menu.add(new SaveAction(false)); JMenuItem saveMenuItemAs = new JMenuItem("SaveAs", new ImageIcon("/images/saveas.gif")); //saveMenuItemAs.setMnemonic(KeyEvent.VK_S); saveMenuItemAs.addActionListener( new SaveAction(true) ); menu.add(saveMenuItemAs); //menu.add(new SaveAction(true)); JMenuItem closeMenuItem = new JMenuItem("Close", KeyEvent.VK_C); closeMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } } ); menu.add(closeMenuItem);

    Read the article

  • How do I create a right click context menu in Java Swing?

    - by Wayne
    I'm working on a school project and we want to implement a right click pop-up menu in the gui. Currently we are doing something like creating a JMenu on right click and setting its location to that of the mouse's position... This seems really ugly and is very buggy, is there any better way of doing this? I'm sure there must be.

    Read the article

  • Context Sensitive JTable (Part 2)

    - by Geertjan
    Now, having completed part 1, let's add a popup menu to the JTable. However, the menu item in the popup menu should invoke the same Action as invoked from the toolbar button created yesterday. Add this to the constructor created yesterday: Collection<? extends Action> stockActions =         Lookups.forPath("Actions/Stock").lookupAll(Action.class); for (Action action : stockActions) {     popupMenu.add(new JMenuItem(action)); } MouseListener popupListener = new PopupListener(); // Add the listener to the JTable: table.addMouseListener(popupListener); // Add the listener specifically to the header: table.getTableHeader().addMouseListener(popupListener); And here's the standard popup enablement code: private JPopupMenu popupMenu = new JPopupMenu(); class PopupListener extends MouseAdapter { @Override public void mousePressed(MouseEvent e) { showPopup(e); } @Override public void mouseReleased(MouseEvent e) { showPopup(e); } private void showPopup(MouseEvent e) { if (e.isPopupTrigger()) { popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } }

    Read the article

  • How to get a JTextField event that started a pop up menu in Java ?

    - by Frank
    I have a JTextField that represents a day, such as "Sunday", when I left mouse click on it, it changes background color, when I right mouse click on it, a pop up menu comes up, after I click on a menu item, such as "1st of month", it gets the value, closes the menu and then change the bgcolor, my code looks like this : JTextField dayHeading=new JTextField("Su"); ...... final JPopupMenu Pmenu; JMenuItem menuItem; Pmenu=new JPopupMenu(); menuItem=new JMenuItem("1st of month"); Pmenu.add(menuItem); menuItem=new JMenuItem("2nd of month"); Pmenu.add(menuItem); ...... menuItem.addMouseListener(new MouseAdapter() { public void mouseReleased(final MouseEvent e) { System.out.println(((JMenuItem)e.getComponent()).getText()); onHeadingClicked(e); // Error : java.lang.ClassCastException: javax.swing.JMenuItem cannot be cast to javax.swing.JTextField // How to get the orininal JTextField event that started this pop up menu, so I can pass it onto onHeadingClicked() ? } }); ...... dayHeading.setEditable(false); dayHeading.setFocusable(false); dayHeading.addMouseListener(new MouseAdapter() { public void mouseReleased(final MouseEvent evt) { if (SwingUtilities.isLeftMouseButton(evt)) onHeadingClicked(evt); else if (SwingUtilities.isRightMouseButton(evt)) Pmenu.show(evt.getComponent(),evt.getX(),evt.getY()); } }); ...... void onHeadingClicked(final java.awt.event.MouseEvent evt) { final javax.swing.JTextField fld=(javax.swing.JTextField) evt.getSource(); ... } My question is : in the menuItem.addMouseListener section, how to get the orininal JTextField event that started this pop up menu, so I can pass it onto onHeadingClicked() ?

    Read the article

  • Rendering another screen on top of main game screen in fullscreen mode

    - by wolf
    my game runs in fullscreen mode and uses active rendering. The graphics are drawn on the fullscreen window in each game loop: public void render() { Window w = screen.getFullScreenWindow(); Graphics2D g = screen.getGraphics(); renderer.render(g, level, w.getWidth(), w.getHeight()); g.dispose(); screen.update(); } This is the screen.update() method: public void update(){ Window w = device.getFullScreenWindow(); if(w != null){ BufferStrategy s = w.getBufferStrategy(); if(!s.contentsLost()){ s.show(); } } } I want to display another screen on my main game screen (menu, inventory etc). Lets say I have a JPanel inventory, which has a grid of inventory cells (manually drawn) and some Swing components like JPopupMenu. So i tried adding that to my window and repainting it in the game loop, which worked okay most of the time... but sometimes the panel wouldn't get displayed. Blindly moving things around in the inventory worked, but it just didn't display. When i alt-tabbed out and back again, it displayed properly. I also tried drawing the rest of the inventory on my full screen window and using a JPanel to display only the buttons and popupmenus. The inventory displayed properly, but the Swing components keep flickering. I'm guessing this is because I don't know how to combine active and passive rendering. public void render() { Graphics2D g = screen.getGraphics(); invManager.render(g); g.dispose(); screen.update(); invPanel.repaint(); } Should i use something else instead of a JPanel? I don't really need active rendering for these screens, but I don't understand why they sometimes just don't display. Or maybe I should just make my own custom components instead of using Swing? I also read somewhere that using multiple panels/frames in a game is bad practice so should I draw everything on one window/frame/panel? If I CAN use JPanels for this, should I add and remove them every time the inventory is toggled? Or just change their visibility?

    Read the article

  • How do you hide a Swing Popup when you click somewhere else.

    - by Casey Watson
    I have a Popup that is shown when a user clicks on a button. I would like to hide the popup when any of the following events occur: The user clicks somewhere else in the application. (The background panel for example) The user minimizes the application. The JPopupMenu has this behavior, but I need more than just JMenuItems. The following code block is a simplified illustration to demonstrate the current usage. import java.awt.*; import java.awt.event.ActionEvent; import javax.swing.*; public class PopupTester extends JFrame { public static void main(String[] args) { final PopupTester popupTester = new PopupTester(); popupTester.setLayout(new FlowLayout()); popupTester.setSize(300, 100); popupTester.add(new JButton("Click Me") { @Override protected void fireActionPerformed(ActionEvent event) { Point location = getLocationOnScreen(); int y = (int) (location.getY() + getHeight()); int x = (int) location.getX(); JLabel myComponent = new JLabel("Howdy"); Popup popup = PopupFactory.getSharedInstance().getPopup(popupTester, myComponent, x, y); popup.show(); } }); popupTester.add(new JButton("No Click Me")); popupTester.setVisible(true); popupTester.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }

    Read the article

1