AWT Popup Menu in Fullscreen Exclusive + JOGL

Our application runs in Fullscreen Exclusive mode and uses JOGL. We want the user to be able to access right-click Popup menus like in other applications. (Obviously, this isn't a game; but I figured I'd post here because game developers are the only ones likely to be familiar with Fullscreen Exclusive.)
On Windows, I was pleasantly suprised to find that popupMenu.show() just works when I'm in Fullscreen Exclusive. The menu appears, works correctly, etc.
On Mac OS X 10.3+, the menu does not appear. I've developed a clumsy workaround (basically, go out of fullscreen exclusive to show the menu, and then go back in when mouse events start coming again). Frankly, the way it works on a Mac is what I expected on the PC. I wouldn't expect a Popup Menu (being another window) to be able to appear over a fullscreen exclusive window.
My question is this: Is the Windows behavior a bug? Is it video driver dependent? (It seems to work OK with all the machines we've tested on... ATI, NVIDIA, Intel) Should I be doing my Mac hack on the Windows platform to avoid some unforseen problem?
Also, any idea what Linux or other platforms would do?

I am not sure why that works in one OS and not the others.
All I can say is that if it was a game, we would draw the popup menu ourself within the frame in our rendering loop, that is garunteed to work in all OS's. But your probably using AWT or SWING components. Sounds like it may be a compadibility issue, I would check the bug lists to see if that is a known issue that is being worked on.

Similar Messages

  • Popups in fullscreen exclusive?

    My game is running in fullscreen exclusive mode but I need to open the occasional dialog box which new shows in front of the fullscreen main frame. Is there any way of making popups such as Dialogs or other frames appear in fullscreen exclusive mode?

    Since when did any game you ever played written in even the most powerful languages and 2d/3d api's ever display a popup during the programs run in fullscreen exclusive mode? (Error popup dialogs that end the game dont count. Unless you 'wanted' your app to end after a popup of course... o_O)
    Now, as for a more efficient/robust/intuitive/cooler etc way to display important information to the user, perhaps your game (I'm assuming its a game due to where this is posted) should draw its own frame lookalike that could function just like a popup, only it resided in the game, and had its own look and feel. ( a look that should undoubtly be way more apealing to your audience than a standard dialog...)

  • JPopupMenu with JInternalFrame, popup menu doesn't work

    hi, i have this problem, as shown in the sample code at the end of this post.. basically, i have a table, and i added a JPopupMenu onto the table.. the popup menu works well when running the table class, though, when i call the table class in a JInternalFrame environment, the popup menu won't work.. anyone know why?
    ///Basic sample table code, when run this alone, the popup menu will work
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TableBasic extends JPanel
         private JTable table;
         public TableBasic()
              String[] columnNames = { "Date", "String", "Integer", "Boolean" };
              Object[][] data =
                   {  { new Date(), "A", new Integer(1), Boolean.TRUE },
                        { new Date(), "B", new Integer(2), Boolean.FALSE },
                        { new Date(), "C", new Integer(9), Boolean.TRUE },
                        { new Date(), "D", new Integer(4), Boolean.FALSE}
              table = new JTable(data, columnNames)
                   //Returning the Class of each column will allow different
                   //renderers to be used based on Class
                   public Class getColumnClass(int column)
                        return getValueAt(0, column).getClass();
              table.setPreferredScrollableViewportSize(table.getPreferredSize());
              JScrollPane scrollPane = new JScrollPane(table);
              add(scrollPane);
         public void createPopupMenu()
              JMenuItem menuItem;
              //Create the popup menu.
              JPopupMenu popup = new JPopupMenu();
              menuItem = new JMenuItem("A popup menu item");
              //menuItem.addActionListener(this);
              popup.add(menuItem);
              menuItem = new JMenuItem("Another popup menu item");
              //menuItem.addActionListener(this);
              popup.add(menuItem);
              //Add listener to the text area so the popup menu can come up.
              MouseListener popupListener = new PopupListener(popup);
              table.addMouseListener(popupListener);
         public static void main(String[] args)
              JFrame frame = new JFrame();
              TableBasic table = new TableBasic();
              table.createPopupMenu();
              frame.setContentPane(table);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.pack();
              //frame.setLocationRelativeTo(null);
              frame.setVisible(true);
         class PopupListener extends MouseAdapter
              JPopupMenu popup;
              PopupListener(JPopupMenu popupMenu)
                   popup = popupMenu;
              public void mousePressed(MouseEvent e)
                   maybeShowPopup(e);
              public void mouseReleased(MouseEvent e)
                   maybeShowPopup(e);
              private void maybeShowPopup(MouseEvent e)
                   if (e.isPopupTrigger())
                        popup.show(e.getComponent(), e.getX(), e.getY());
    ///when integrate the previous table into here, popup menu won't work
    import java.awt.*;
    import javax.swing.*;
    public class InternalFrameBasic
         extends JFrame
         //implements ActionListener
         private JDesktopPane desktop;
         private JInternalFrame menuWindow;
         public static final int desktopWidth = 800;
         public static final int desktopHeight = 700;
         public InternalFrameBasic(String title)
              super(title);
              //Set up the GUI.
              desktop = new JDesktopPane();
              desktop.putClientProperty("JDesktopPane.dragMode", "outline");
              //Because we use pack, it's not enough to call setSize.
              //We must set the desktop's preferred size.
              desktop.setPreferredSize(new Dimension(desktopWidth, desktopHeight));
              setContentPane(desktop);
              createMenuWindow();
              desktop.add(menuWindow); //DON'T FORGET THIS!!!
              Dimension displaySize = menuWindow.getSize();
              menuWindow.setSize(desktopWidth, displaySize.height);
         private void createMenuWindow()
              menuWindow =
                             new JInternalFrame("Event Watcher", true, //resizable
                                                                                                   true, //closable
                                                                                                   false, //not maximizable
                                                                                                   true); //iconifiable
              menuWindow.setContentPane(new TableBasic());
              menuWindow.pack();
              menuWindow.setVisible(true);
          * Create the GUI and show it.  For thread safety,
          * this method should be invoked from the
          * event-dispatching thread.
         private static void createAndShowGUI()
              //Make sure we have nice window decorations.
              //JFrame.setDefaultLookAndFeelDecorated(true);
              //Create and set up the window.
              JFrame frame = new InternalFrameBasic("Example Internal Frame");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              //Display the window.
              frame.pack();
              frame.setVisible(true);
         public static void main(String[] args)
              //Schedule a job for the event-dispatching thread:
              //creating and showing this application's GUI.
              javax.swing.SwingUtilities.invokeLater(new Runnable()
                   public void run()
                        createAndShowGUI();
    }

    table.createPopupMenu();The above line should not be in the main method. It should be in the constructor class of TableBasic.
    You never execute that method in your InternalFrameBasic class to the mouse listener never gets added to the table.

  • Event Handling in Fullscreen Exclusive Mode???????

    WIndows XP SP2
    ATI 8500 All-In-Wonder
    JDK 1.6
    800x600 32dpi 200 refresh
    1-6 buffer strategy.
    the graphic rendering thread DOESN'T sleep.
    Here's my problem. I have a bad trade off. In fullscreen exclusive mode my animation runs <30 fps and jerks when rendering. i.e. stop and go movement (not flickering/jittering just hesitant motion) when the animation is running. I solved this problem by raising the thread priority of the rendering (7-8). . . this resulted in latency/no activity for my input events both key and mouse. For instance closing the program alt-f4 will arbitrarily fail or be successful when the thread priority is raised above 6.
    How does one accomplish a >30 fps and Instant event handling simultaneously in Fullscreen Exclusive Mode?
    Is there a way to raise thread priority for event handling?
    Ultimately I want to be able to perform my animations and handle key and mouse input events without having a visible 'hiccups' on the screen.
    Much Appreciated!

    If I remember correctly the processor is a 1.4(or)6ghz AMD Duron
    Total = 1048048kb
    Available = 106084kb
    Sys Cache = 211788kb
    PF Usage = 1.01 GB
    I solved some of the problem after posting this thread. . . .
    I inserted a thread.sleep(1) and my alt-f4 operation worked unhindered with the elevated thread priority.
    I haven't tested it with mouse event or any other key event but at the moment it looks I may have solved the problem.
    If so, my next question will be is there a way to reduce the amount of cpu power needed to run the program.
    I'm afraid that the other classes that I'm adding will actually become even more process consuming than the actually rendering thread.
    public class RenderScreen extends Thread
      // Screen Rendering status code
      protected final static int RUNNING = 0,
                                 PAUSED = -1;
      // frames per second and process time counters
      protected long now = 0, fps = 0, fpsCount = 0, cycTime = 0;
      // thread status
      protected int status = 0;
      protected Screen screen;
      public void setStatus(int i){ status = i; };
      public void setTarget(Screen screen){ this.screen=screen; };
      public void run()
        setName("Screen Render");
        screen.createBufferStrategy(1);
        screen.strategy = screen.getBufferStrategy();
        for(;;)
          if(status == RUNNING)
            now = System.currentTimeMillis();
            while(System.currentTimeMillis() <= now+1000)
              // call system processes
              // fps increment / repaint interface
              fpsCount++;
              screen.renderView();
              try { Thread.sleep(1);}catch(InterruptedException ie){ ie.printStackTrace(); }
            fps = fpsCount;
            cycTime = System.currentTimeMillis() - (now + 1000);
            fpsCount=0;
      public RenderScreen(){};
      public RenderScreen(Screen screen){ this.screen=screen; };
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import javax.swing.*;
    public class Screen extends Window
      BufferedImage image = new BufferedImage(800,600,BufferedImage.TYPE_INT_RGB);
      Graphics2D gdd = image.createGraphics();
      MediaTracker tracker = new MediaTracker(this);
      Image bground = getToolkit().getImage("MajorityRule.jpg"),
            bawl = getToolkit().getImage("bawl.gif");
      RenderScreen rScreen = new RenderScreen(this);
      BufferStrategy strategy;
      Graphics g;
      Rectangle rect = new Rectangle(400,0,150,150);
      //Game game = new Game();
      public void renderView()
        g = strategy.getDrawGraphics();
        //--------- Game Procedures [start]
        gdd.drawImage(bground,0,0,this);
        gdd.drawString("fps: ["+rScreen.fps+"] Cycle Time: ["+rScreen.cycTime+"]",0,10);
        //--------- Game Procedures [end]
        //---------test
        gdd.drawImage(bawl,rect.x,rect.y,rect.width,rect.height,this);
        rect.translate(0,1);
        g.drawImage(image,0,0,this);
        //g.dispose();
        strategy.show();
      public Screen(JFrame frame)
        super(frame);
        try
          tracker.addImage(bground,0);
          tracker.addImage(bawl,1);
          tracker.waitForAll();
        catch(InterruptedException ie){ ie.printStackTrace(); }
        setBackground(Color.black);
        setForeground(Color.white);
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MajorityRule extends JFrame
      // Graphic System Handlers
      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      GraphicsDevice gd = ge.getDefaultScreenDevice();
      GraphicsConfiguration gc = gd.getDefaultConfiguration();
      Screen screen = new Screen(this);
      Paper paper = new Paper();
      public void windowed()
        paper.setSize(getWidth(),getHeight());
        getContentPane().add(paper);
        setResizable(false);
        setVisible(true);
      public void fullscreen()
        DisplayMode dMode = new DisplayMode(800,600,32,200);
        screen.setBounds(0,0,800,600);
        if (gd.isFullScreenSupported()) gd.setFullScreenWindow(screen);
        if (gd.isDisplayChangeSupported()){ gd.setDisplayMode(dMode); };
        screen.setIgnoreRepaint(true);
        screen.setVisible(true);
        screen.rScreen.setPriority(Thread.MAX_PRIORITY);
        screen.rScreen.start();
        screen.requestFocus();
      public MajorityRule(String args[])
        setTitle("Majority Rule [Testing Block]");
        setBounds(0,0,410,360);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        getContentPane().setLayout(null);
        if (args.length > 0 && args[0].equals("-window")) windowed();
        else fullscreen();
      public static void main(String args[])
        new MajorityRule(args);
    };

  • "Java Applet Window" appears in my popup menu

    Hello
    I have added a popup menu to my applet but whenever the popup menu appears, I also get the text "Java Applet Window" at its bottom.
    What is causing this?
    Can I get rid of it?

    Yes you can add a local user policy or local system policy that grants an AWT permission that regards "Java Applet Window" more precisely permission java.awt.AWTPermission "showWindowWithoutWarningBanner";
    You can use a tool to add policy, create new policy files etc. Read about "policytool" in http://java.sun.com/j2se/1.4.1/docs/tooldocs/tools.html
    Probably, signing tha applet jar, you can obtain necessary permission without modifing local policy. But I'm not sure.
    Stefano.

  • Swing Components and Fullscreen Exclusive

    Hi, I am trying to write a program that can switch between full screen and windowed mode seamlessly, while still being able to use standard swing components. I have never worked with the full screen exclusive mode before and am having trouble getting the components to repaint properly.
    The following code works fine in the windowed and undecorated modes, however when I switch to fullscreen exclusive mode all components disappear and only repaint upon mouseover or other interaction. Calls to repaint do not make any difference.
    import java.awt.Dimension;
    import java.awt.DisplayMode;
    import java.awt.FlowLayout;
    import java.awt.GraphicsDevice;
    import java.awt.GraphicsEnvironment;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.WindowConstants;
    public class FullscreenTests {
         private static boolean hwlast = false;
         private static GraphicsDevice dev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
         public static void main(String[] args) {
              final JFrame fMain = new JFrame("Title");
              fMain.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              fMain.getRootPane().setLayout(new FlowLayout());
              JButton win = new JButton("Windowed");
              win.addActionListener(new ActionListener () {
                   public void actionPerformed (ActionEvent e) {
                        setWindowed(fMain);
              fMain.getRootPane().add(win);
              JButton ful = new JButton("Fullscreen");
              ful.addActionListener(new ActionListener () {
                   public void actionPerformed (ActionEvent e) {
                        setFullscreen(fMain);
              fMain.getRootPane().add(ful);
              JButton hw = new JButton("HW Fullscreen");
              hw.addActionListener(new ActionListener () {
                   public void actionPerformed (ActionEvent e) {
                        setHWFullscreen(fMain);
              fMain.getRootPane().add(hw);
              setWindowed(fMain);
         public static void setWindowed(JFrame f) {
              if (hwlast == true) {
                   dev.setFullScreenWindow(null);
                   hwlast = false;
              f.dispose();
              f.setIgnoreRepaint(false);
              f.setUndecorated(false);
              Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
              f.setSize(new Dimension(808,634));
              f.setMinimumSize(new Dimension(808,634));
              f.setLocation((d.width-f.getWidth())/2, (d.height-f.getHeight())/2);
              f.setVisible(true);
         public static void setHWFullscreen(JFrame f) {
              hwlast = true;
              f.dispose();
              f.setUndecorated(true);
              f.setIgnoreRepaint(true);
              f.setVisible(true);
              dev.setFullScreenWindow(f);
              dev.setDisplayMode(new DisplayMode(800, 600, 32, DisplayMode.REFRESH_RATE_UNKNOWN));
         public static void setFullscreen(JFrame f) {
              if (hwlast == true) {
                   dev.setFullScreenWindow(null);
                   hwlast = false;
              f.dispose();
              f.setIgnoreRepaint(false);
              f.setUndecorated(true);
              f.setSize(Toolkit.getDefaultToolkit().getScreenSize());
              f.setLocation(0,0);
              f.setVisible(true);
    }On the same note, if there are better ways of doing this I would be glad to know. This is just a quick test so I haven't done any checks etc when switching to fullscreen exclusive.

       public static void setHWFullscreen (JFrame f) {
          hwlast = true;
          f.dispose ();
          f.setUndecorated (true);
          f.setIgnoreRepaint (true);
          // add this
          Graphics g = f.getGraphics ();
          f.paintAll (g);
          f.setVisible (true);
          dev.setFullScreenWindow (f);
          dev.setDisplayMode (new DisplayMode (800, 600, 32, DisplayMode.REFRESH_RATE_UNKNOWN));
       }db

  • JMF video while in Fullscreen Exclusive

    I am trying to show a video (using JMF) in my window while in fullscreen exclusive mode. Its for a game. It works occasionally. What I've done is turned of the repetitive rendering (from the game loop), and just added the visual component to the window (it can do its own painting). Sometimes it works fine, other times you just hear the sound, and other times its just grey or black.
    Does anybody have any idea how to get the current frame, and draw it so that I can keep the repetitive rendering (from the game loop) running.
    Any other ideas are appreciated too.

    Never written a fullscreen exclusive application. In fact, I've never even heard of such a thing.
    http://download.oracle.com/javase/tutorial/extra/fullscreen/exclusivemode.html
    "In full-screen exclusive applications, painting is usually done actively by the program itself"
    Ah. So no, I don't think JMF would support that because it's not going to be actively rendering, only passively rendering in response to paint requests. It's AWT/Swing based, after all...
    But, the fact that JMF doesn't support it does not mean JMF can't support it. JMF provides a custom Renderer interface which you could implement to actively render the stuff. It'll essentially give you a copy of the video frame in a Buffer object which you can then turn into an image using the BufferToImage class and then render that however you'd render an image for a full screen exclusive application...

  • JMF In Fullscreen Exclusive Mode

    Hello,
    I was wondering if anyone could let me know if JMF is supported inside a Fullscreen Exclusive Application? I seem to have no problem setting up JMF Video output for a standard JFrame/Frame, but when setting a "fullscreenWindow" the Player turns black. I cannot seem to find any posts on whether this is supported or if there are bugs when in Fullscreen Exclusive Mode.
    Thanks
    -Michael Morris

    Never written a fullscreen exclusive application. In fact, I've never even heard of such a thing.
    http://download.oracle.com/javase/tutorial/extra/fullscreen/exclusivemode.html
    "In full-screen exclusive applications, painting is usually done actively by the program itself"
    Ah. So no, I don't think JMF would support that because it's not going to be actively rendering, only passively rendering in response to paint requests. It's AWT/Swing based, after all...
    But, the fact that JMF doesn't support it does not mean JMF can't support it. JMF provides a custom Renderer interface which you could implement to actively render the stuff. It'll essentially give you a copy of the video frame in a Buffer object which you can then turn into an image using the BufferToImage class and then render that however you'd render an image for a full screen exclusive application...

  • Popup Menu simple question

    Hi ive got my applet and I want to respond with a popup menu when the user right clicks
    Will java.awt.popupmenu provide a popup menu with the look and feel of the OS's popup menus?
    Im using a simple canvas in my applet. Is this the best class to do a popup menu?
    Thanks

    bump
    Any1?

  • Popup menu does not show in JTextField

    I have a JPanel with a popup menu that works perfectly, as long as the right mouse button is clicked on the JPanel. However the popup menu does not show if the right mouse button is clicked on a JTextField that is within the JPanel.
    What has to be done that the popup menu shows always?
    this.addMouseListener(new java.awt.event.MouseAdapter()
    public void mouseReleased(MouseEvent e)
    this_mouseReleased(e);
    protected void this_mouseReleased(MouseEvent e)
    if (e.isPopupTrigger())
    popPopup.show(this, e.getX(), e.getY());

    There are up to 20 JTextFields in the JPanels an the application has a lot of JPanels of course. Adding the listener to each and every JTextField means a lot of extra code. Is there really no generic solution to this problem???

  • Popup menu on menuItem

    I want to show the popupmenu when users do the right click on the menuitem to do something like the mozilla or internet explorer Favorites menu which can be do right click to show the popup.
    I tried this, but i always have the following problems:
    1) I open the popupMenu with the popup.show( jmenuitem, mouseEvent.getX(), mouseEvent.getY())
    I got the error : java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location
    private JMenuItem getAddMenuItem() {
              if (addMenuItem == null) {
                   addMenuItem = new JMenuItem();
                   addMenuItem.setText(" Favourites    ");
                   addMenuItem.addMouseListener(new MouseAdapter() {
                        public void mousePressed(java.awt.event.MouseEvent e){
                             System.out.println("Mouse Pressed: "+e);
                             if(SwingUtilities.isRightMouseButton(e)){
                                   System.out.println("Right mouse action");
                             if(SwingUtilities.isLeftMouseButton(e)){
                                  System.out.println("Left Mouse action");
                                                   //Here i will open a dialog for the user
                                     public void mouseReleased(java.awt.event.MouseEvent e) {
                             System.out.println("Mouse Released: "+e);
                             if(SwingUtilities.isRightMouseButton(e)){
                                   System.out.println("Right mouse action");
                                   addMenuItem.add(getPopUpMenu());
                                   if (popUpMenu.isPopupTrigger(e)){
                                        System.out.println("Triggered2");
                                        popUpMenu.show(e.getComponent(), e.getX(), e.getY());
                             if(SwingUtilities.isLeftMouseButton(e)){
                                  System.out.println("Left Mouse action");
                   });     so how can i make the menuItem available on the screen to add the popup menu to it?

    I didn't see your code but a meunitem on a menu can be another menu. I think that shoud be enough for your requirement.

  • Display Popup menu on pen hold

    I've written several separate apps for PDAs that we've been using for awhile now. There is a new need to copy and paste data between these multiple applications.
    While I can get this working simply by using buttons, I'd rather go with a more elegant approach, something like displaying a drop-down menu when the user holds the pen down on the Textfield.
    These textfields are custom extensions to Textfield and therefore it's easy to capture this logic once, problem is I can't get a popup menu to display. I was trying to use MouseListeners, etc. but that doesn't seem to do anything.
    FWIW, we run our apps on CrEme 3.25 and have these apps written in AWT.
    Thanks.

    Well, I could find no way to have a pen hold down to trigger a popup (the isPopupTrigger() method didn't work, checking for BUTTON3_MASK didn't work) so I implemented a customized version using a threaded timer.
    Thanks.

  • Popup menu on tab components disables JTabbedPane mouse clicks

    When I add a popup menu to the tab components, the underlying JTabbedPane doesn't respond to any mouse click. How can we solve this?
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class TabPopupDemo extends JFrame {
        private JLabel jLabel1;
        private JLabel jLabel2;
        private JMenuItem jMenuItem1;
        private JPopupMenu jPopupMenu1;
        private JTabbedPane jTabbedPane1;
        public TabPopupDemo() {
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setSize(400, 300);
            setLocationRelativeTo(null);
            jPopupMenu1 = new JPopupMenu();
            jMenuItem1 = new JMenuItem("jMenuItem1");
            jTabbedPane1 = new JTabbedPane();
            jLabel1 = new JLabel("jLabel1");
            jLabel2 = new JLabel("jLabel2");
            jPopupMenu1.add(jMenuItem1);
            jTabbedPane1.addTab(null, jLabel1);
            jTabbedPane1.addTab(null, jLabel2);
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            int tabCount = jTabbedPane1.getTabCount();
            for (int i = 0; i < tabCount; i++) {
                JLabel jLabel = new JLabel("Testing the tab" + (i + 1));
                jTabbedPane1.setTabComponentAt(i, jLabel);
                jLabel.setName(String.valueOf(i));
                jLabel.setComponentPopupMenu(jPopupMenu1);
            jPopupMenu1.addPopupMenuListener(new PopupMenuListener() {
                public void popupMenuCanceled(final PopupMenuEvent evt) {
                public void popupMenuWillBecomeInvisible(final PopupMenuEvent evt) {
                public void popupMenuWillBecomeVisible(final PopupMenuEvent evt) {
                    JPopupMenu source = (JPopupMenu) evt.getSource();
                    JLabel invoker = (JLabel) source.getInvoker();
                    JLabel component = (JLabel) jTabbedPane1.getComponentAt(Integer.parseInt(invoker.getName()));
                    jMenuItem1.setText(invoker.getText() + ":  " + component.getText());
        public static void main(final String args[]) {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new TabPopupDemo().setVisible(true);
    }

    I don't know what the best solution would be.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class TabPopupDemo2 extends JFrame {
      private JLabel jLabel1;
      private JLabel jLabel2;
      private JMenuItem jMenuItem1;
      private JPopupMenu jPopupMenu1;
      private JTabbedPane jTabbedPane1;
      public TabPopupDemo2() {
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setSize(400, 300);
        setLocationRelativeTo(null);
        jPopupMenu1 = new JPopupMenu();
        jMenuItem1 = new JMenuItem("jMenuItem1");
        jTabbedPane1 = new JTabbedPane();
        jLabel1 = new JLabel("jLabel1");
        jLabel2 = new JLabel("jLabel2");
        jPopupMenu1.add(jMenuItem1);
        jTabbedPane1.addTab(null, jLabel1);
        jTabbedPane1.addTab(null, jLabel2);
        getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
        int tabCount = jTabbedPane1.getTabCount();
        TabMouseListener tml = new TabMouseListener(jTabbedPane1);
        for (int i = 0; i < tabCount; i++) {
          JLabel jLabel = new JLabel("Testing the tab" + (i + 1));
          jTabbedPane1.setTabComponentAt(i, jLabel);
          jLabel.setName(String.valueOf(i));
          jLabel.addMouseListener(tml);
          jLabel.setComponentPopupMenu(jPopupMenu1);
        jPopupMenu1.addPopupMenuListener(new PopupMenuListener() {
          public void popupMenuCanceled(PopupMenuEvent evt) {}
          public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {}
          public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            //JPopupMenu source = (JPopupMenu) e.getSource();
            //JLabel invoker = (JLabel) source.getInvoker();
            int index = jTabbedPane1.getSelectedIndex();
            JLabel invoker = (JLabel) jTabbedPane1.getTabComponentAt(index);
            JLabel component = (JLabel) jTabbedPane1.getComponentAt(index);
            jMenuItem1.setText(invoker.getText() + ":  " + component.getText());
      static class TabMouseListener extends MouseAdapter{
        private final JTabbedPane tp;
        TabMouseListener(JTabbedPane tabbedPane) {
          this.tp = tabbedPane;
        private void dispatchEvent(MouseEvent me) {
          JLabel l = (JLabel)me.getSource();
          tp.dispatchEvent(SwingUtilities.convertMouseEvent(l,me,tp));
        public void mouseClicked(MouseEvent me)  { dispatchEvent(me); }
        public void mouseEntered(MouseEvent me)  { dispatchEvent(me); }
        public void mouseExited(MouseEvent me)   { dispatchEvent(me); }
        public void mousePressed(MouseEvent me)  { dispatchEvent(me); }
        public void mouseReleased(MouseEvent me) { dispatchEvent(me); }
      public static void main(final String args[]) {
        EventQueue.invokeLater(new Runnable() {
          public void run() { new TabPopupDemo2().setVisible(true); }
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class TabPopupDemo3 extends JFrame {
      private JLabel jLabel1;
      private JLabel jLabel2;
      private JMenuItem jMenuItem1;
      private JPopupMenu jPopupMenu1;
      private JTabbedPane jTabbedPane1;
      public TabPopupDemo3() {
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setSize(400, 300);
        setLocationRelativeTo(null);
        jPopupMenu1 = new JPopupMenu();
    //     jPopupMenu1 = new JPopupMenu() {
    //       public void show(Component c, int x, int y) {
    //         int i = jTabbedPane1.indexAtLocation(x, y);
    //         if(i>=0) {
    //           JLabel tab = (JLabel) jTabbedPane1.getTabComponentAt(i);
    //           JLabel component = (JLabel) jTabbedPane1.getComponentAt(i);
    //           jMenuItem1.setText(tab.getText() + ":  " + component.getText());
    //           super.show(c, x, y);
        jMenuItem1 = new JMenuItem("jMenuItem1");
        jTabbedPane1 = new JTabbedPane();
        jTabbedPane1.setComponentPopupMenu(jPopupMenu1);
        jLabel1 = new JLabel("jLabel1");
        jLabel2 = new JLabel("jLabel2");
        jPopupMenu1.add(jMenuItem1);
        jTabbedPane1.addTab(null, jLabel1);
        jTabbedPane1.addTab(null, jLabel2);
        getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
        int tabCount = jTabbedPane1.getTabCount();
        for (int i = 0; i < tabCount; i++) {
          JLabel jLabel = new JLabel("Testing the tab" + (i + 1));
          jTabbedPane1.setTabComponentAt(i, jLabel);
          jLabel.setName(String.valueOf(i));
          //jLabel.setComponentPopupMenu(jPopupMenu1);
        jPopupMenu1.addPopupMenuListener(new PopupMenuListener() {
          public void popupMenuCanceled(final PopupMenuEvent evt) {}
          public void popupMenuWillBecomeInvisible(final PopupMenuEvent evt) {}
          public void popupMenuWillBecomeVisible(final PopupMenuEvent evt) {
            JPopupMenu source = (JPopupMenu) evt.getSource();
            int i = jTabbedPane1.getSelectedIndex();
            JLabel tab = (JLabel) jTabbedPane1.getTabComponentAt(i);
            JLabel component = (JLabel) jTabbedPane1.getComponentAt(i);
            if(tab.getMousePosition()!=null) {
              jMenuItem1.setText(tab.getText() + ":  " + component.getText());
            }else{
              jMenuItem1.setText("aaaaaaaaa");
      public static void main(final String args[]) {
        EventQueue.invokeLater(new Runnable() {
          public void run() { new TabPopupDemo3().setVisible(true); }
    }

  • Popup menu appears behind canvas component

    Has anybody encountered this problem?
    I attach the popup menu to the canvas component, like this:
    public void mousePressed(MouseEvent e)
         if (e.getSource() == psuCanvas && e.getButton() == MouseEvent.BUTTON3)
              pmenu.show((Component)psuCanvas, e.getX(), e.getY());
              contextText.setText("Right Click!!!");
    The popup menu is only visible when I click the edge of the Canvas component, that is how I know that the popup is actually showing but behind the Canvas component!!!
    Please help

    You mean your 1 step of calling "JPopupMenu.setDefaultLightWeightPopupEnabled(false);"?
    That method is meant specifically for using popup menus when you are mixing AWT and Swing components. The reason is because of the problem you first posted about. It's a way to get around that problem. But really, it's more of a hack that is used when dealing with old AWT-based components which you can't (or won't), for whatever reason, "update" to Swing versions. (Say from a 3rd-party library).
    It is not recommended to mix AWT and Swing components, as already mentioned. The provided link above is an article that explains the issues with this. The fact that you can doesn't mean you should.
    If you are writing this Canvas subclass yourself, and it's going to be typically used in a Swing application, you will have problems later, most likely. For example, why don't you try puting your Canvas class in a JScrollPane so you can make it bigger then the window and scrollable? You'll have scrollbar visibility issues. Fine, you can use java.awt.ScrollPane, I guess. Then I can think of several things one might do with JLayeredPanes which would create problems as well. And there is no simple "setDefaultLightWeightEnabled()" option to fix those.
    So eventually, as your app, or library, matures, you start running into these problems cuz you are using AWT components where you should be using Swing components, and you start making more hack-like fixes for all these problems like using setDefaultLightWeightPopupEnabled() and explicit sizing instead of layout managers and limiting yourself to what you can do with your components.
    That's why.

  • Application wide popup menu for JTextComponent descendants

    Hi!
    I'm working on large project with reach Swing GUI and I got stuck with one small but wery annoing problem. I have to append simple popup menu to all text input fields (JTextComponent descendants) in whole application. I'm realy lazy to append mouse listener on each component, so I'm asking, is there any way to append "default" popup menu for all components. Please, don't answer about custom components instead of Swing plain JTextComponent descendants - it's worse to change classes for all fields then add mouse listener to them.
    As an example of what I want I could forward you to UIManager.put() method, which affects all properties of component behaviour thoughout application. I want to find same solution, maybe there any registry or smth. else in API.
    Than you in advice.

    You could always try extending something like MetalTextFieldUI so that it adds the listeners to the text field automatically. You'd then need to register that UI class with the UIManager at startup:
    public class MyTextFieldUI extends MetalTextFieldUI {
      protected void installListeners() {
        super.installListeners();
        // TODO - Install your listener here
      protected void uninstallListeners() {
        super.uninstallListeners();
        // TODO - Uninstall your listener here
    UIManager.put("TextFieldUI", MyTextFieldUI.class.getName());Personally, I think you're just being lazy... getting your components to extend a subclass of JTextField should be no trouble at all and will leave you with clearer code.
    Hope this helps.

Maybe you are looking for

  • With Mac OS X can the system.log files be safely deleted?

    I just did a search of my HD using OmniDiskSweeper, and there's a file called system.log that's 8GB The path is /private/var/log/system.log Can this file be deleted without any bad effects? Wouldn't the system just create a new one when needed? I ope

  • 10.8.4 Screen Brightness Keys No Longer Work

    I ran updates this morning and I assume it updated to 10.8.4 from the app store updates tab. After this update and booting back up the screen brightness keys no longer work. F1 and F2 keys do nothing and they worked fine before the update. Anyone els

  • Is there a way to set the default media kind in itunes

    I hate having to change every movie I make and add to itunes from home video to movie.  Does anyone know a way to change the default media type.  There must be a way using terminal.

  • How can I install PS Elements 10 when get error message, serial number not valid

    I have a new computer (PC Windows)  and want to install my PS Elements 10  and Light Room 5.2.  When I try to do so I get the error message that my serial number is not valid.  I have used the help/support and have done what suggested but nothing see

  • Passing Hidden varable in URL

    Hi, I am trying to pass hidden variable as URL parameter. Please could someone correct me what is wrong here as I always get null value though there is a value in folderId: <input type=hidden id="folderId" value='<c:out value="${bean.folderId}"/>'/>