Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8096597

[Swing] Not possible to select MenuItem in JFXPanel on Linux

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 8u20
    • 8u5
    • javafx
    • Red Hat Enterprise Linux 6.2
      Xorg 1.10.4
      Gnome 2.28.2

    Description

      When a scene with a MenuBar is hosted in a JFXPanel the MenuItems do not change their appearance on mouseover and do not respond to mouse clicks.

      This problem also affects ChoiceBox controls as well.

      This problem only occurs on Linux. It does not occur on Windows 7.
      This is a regression from 7u55. The problem does not occur on both Windows or Linux when using Java 7

      The example below demonstrates the problem.

      import java.awt.HeadlessException;

      import javafx.application.Platform;
      import javafx.embed.swing.JFXPanel;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Menu;
      import javafx.scene.control.MenuBar;
      import javafx.scene.control.MenuItem;
      import javafx.scene.layout.BorderPane;

      import javax.swing.JFrame;

      public class JFxPanelMenuTest extends JFrame {

          public JFxPanelMenuTest() throws HeadlessException {
              super("FX Menu Test JFXPanel");
              setSize(200, 200);
              final JFXPanel fxPanel = new JFXPanel();
              add(fxPanel);
              Platform.runLater(new Runnable() {
                  @Override
                  public void run() {
                      fxPanel.setScene(buildScene());
                  }
              });
          }

          private Scene buildScene() {
              BorderPane fxContent = new BorderPane();
              MenuBar menus = new MenuBar();
              Menu menu = new Menu("First");
      menu.getItems().addAll(createMenuItem("Item One"), createMenuItem("Item Two"), createMenuItem("Item Three"));
              menus.getMenus().add(menu);
              fxContent.topProperty().set(menus);
              return new Scene(fxContent);
          }

          private MenuItem createMenuItem(final String name) {
              MenuItem menuItem = new MenuItem(name);
              menuItem.setOnAction(new EventHandler<ActionEvent>() {
      @Override
      public void handle(ActionEvent arg0) {
      System.out.println("Mouse clicked " + name);
      }
      });
              return menuItem;
          
          }

          public static void main(String[] args) {
              JFxPanelMenuTest menuTest = new JFxPanelMenuTest();
              menuTest.setDefaultCloseOperation(EXIT_ON_CLOSE);
              menuTest.setVisible(true);
          }
      }

      Attachments

        Issue Links

          Activity

            People

              anthony Anthony Petrov (Inactive)
              duke J. Duke
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported: