nx-libs icon indicating copy to clipboard operation
nx-libs copied to clipboard

Invisible menu bar in java apps

Open uli42 opened this issue 8 years ago • 6 comments

When running the example from http://alvinalexander.com/java/java-menubar-example-jmenubar-jframe in a rootless x2go session the window gets shown but the menu bar is not visible until the window is moved or resized. This happens (for me) in about 85% of all starts. It does not happen with all window managers since some of them take care of placing the window and this seems to trigger a event for the example program so that the window gets repainted. I was able to see this in Unity and sometimes kwin.

How to reproduce:

  • save this stripped down version of the example somewhere:
import java.awt.*;
import javax.swing.*;

public class JavaMenuBarExample implements Runnable
{
  private JFrame frame;
  private JMenuBar menuBar;
  private JMenu fileMenu;

  public static void main(String[] args)
  {
    SwingUtilities.invokeLater(new JavaMenuBarExample());
  }

  public void run()
  {
    frame = new JFrame("Java Menubar Example");
    menuBar = new JMenuBar();
    fileMenu = new JMenu("File");
    menuBar.add(fileMenu);
    frame.setJMenuBar(menuBar);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setPreferredSize(new Dimension(400, 300));
    frame.pack();
    frame.setVisible(true);
  }
}
  • compile it:
> javac JavaMenuBarExample.java
  • open an x2go rootless session (x2go: session type: application, command: /usr/bin/xterm)

  • run the example from the xterm:

    > java JavaMenuBarExample
    

    -> menu bar is missing: missing_menubar

  • move the example window -> menu bar appears: after_movement


uli42 avatar Aug 02 '16 19:08 uli42

I now figured out that this is NOT related to using the nx transport. It happens in rootless session, regardless of the transport. You can simply run

nxagent -ac -R :99

and from another shell

java  JavaMenuBarExample

to trigger that bug

uli42 avatar Aug 06 '16 21:08 uli42

I have done some debugging. It looks to me like the problem is the way java tries to detect window managers. By adding some debug output for the java XWM class to the example above I can see that java does not detect a window manager in the rootless session. I think it should detect the outside window manager instead. Further, java decides that the example window`s parent ist the root window. This is true but not helpful, since the rootless root window should not be relevant here but the outside root window...

I also found a very similar bug (from 2004) in the java bug tracker: https://bugs.openjdk.java.net/browse/JDK-5023533

And: when adding debug output the problem does not happen not that often anymore. So it seems to be caused by some kind of race condition, too.

uli42 avatar Aug 09 '16 19:08 uli42

This problem often occurs when using awt/swing and a fancy window manager like awesome. Often it helps when setting

_JAVA_AWT_WM_NONREPARENTING=1; export _JAVA_AWT_WM_NONREPARENTING or faking the windowmanager with wmname Sawfish or wmname LG3D

woglinde avatar Aug 10 '16 07:08 woglinde

On Wed, Aug 10, 2016 at 9:13 AM, Henning Heinold [email protected] wrote:

This problem often occurs when using awt/swing and a fancy window manager like awesome. Often it helps when setting

_JAVA_AWT_WM_NONREPARENTING=1; export _JAVA_AWT_WM_NONREPARENTING or faking the windowmanager with wmname Sawfish or wmname LG3D

I have tried all those - to no avail unfortunately...

Uli

uli42 avatar Aug 10 '16 07:08 uli42

This is still happening with today's HEAD (3731a996dce9adf1c6f398cc1cdec2909588a7ee), also with openjdk-1.8.0.151-1.b12

uli42 avatar Dec 11 '17 13:12 uli42

see #830 for a patch passing down WM information.

uli42 avatar Dec 17 '19 23:12 uli42