3

I am trying to use javafx2 on scala with scalafx.

I wrote a simple application and add a menu and a menu item. When i click the menu and hover on the menu item it some times not highlight the menu and as a result it cannot be clicked. In order to check if i am doing something wrong in my code i run the exactly same code in a windows machine and it just works.

I cannot understand why this is happening. I guess it has something to do with unity or gnome or linux in general.

Have anybody else experienced the same problem? Is there any way to fix it or overcome it?

Thanks i advance

Code example: Only the menu has the strange behaviour

package com.msp.ippokratis.ui
import scalafx.Includes._
import scalafx.collections.ObservableBuffer
import scalafx.collections.ObservableBuffer.observableBuffer2ObservableList
import scalafx.application.JFXApp
import scalafx.application.JFXApp.PrimaryStage
import scalafx.scene.Scene
import scalafx.scene.layout.{BorderPane,FlowPane,Priority}
import scalafx.scene.control.{MenuBar,MenuItem,Menu,Button,ComboBox}
import scalafx.event.ActionEvent
object Exampl extends JFXApp {
  stage = new PrimaryStage {
    scene = new Scene {
      content = new BorderPane {
        prefHeight = 400
        prefWidth = 400
        top = new MenuBar {
          menus = Seq(
            new Menu {
              text = "File"
              items = Seq(
                new MenuItem {
                  text = "Println"
                  onAction = (evt: ActionEvent) => {
                    println("Clicked Menu Item Println")
                  }
                })
            })
        }
        center = new FlowPane {
          hgrow  = Priority.ALWAYS
          content = Seq(
            new Button {
              text = "Sample Button"
              onAction = (evt: ActionEvent) => {
                println("Button Clicked")
              }
            },
            new ComboBox {
              val seq = List("Apple", "Orange", "Mango", "Banana").toSeq
              items = ObservableBuffer(seq.asInstanceOf[Seq[Nothing]])
              onAction = (evt: ActionEvent) => {
                println("Combobox")
              }
            })
        }
      }
    }
  }
}

Edit 1 : If i click the menu and navigate with the keyboard and press enter it just works on linux too.

Iraklis
  • 810
  • 5
  • 14
  • 1
    You may have a better chance of response if you include some code that compiles and exhibits the strange behavior (and if possible is reduced to just the issue in question). – huynhjl May 06 '13 at 12:16
  • Try adding -Dsun.java2d.pmoffscreen=false for Java 6, or -Dsun.java2d.xrender=true for Java 7. See updated answer below. – nadavwr May 07 '13 at 10:35

1 Answers1

2

In the past, I recall encountering two issues that impacted Java-based user interfaces on linux:

Wrong shared objects being loaded

SWT applications, such as Eclipse itself, displayed odd mouse interaction. I think this was only the case when SWT shared libraries were installed system-wide from the Ubuntu repository. In order to be reasonably certain this isn't the case, try to run everything (JRE, JavaFX) from your home directory, adjusting paths as necessary. If you're extra paranoid, remove any JRE packages and anything that depends on them -- especially if it has 'jni' in the package name.

More likely: disable compositing

Try logging into a session where compositing isn't in effect. For example, try installing 'openbox', logging out, and when you are promoted to log in choose the new openbox session. If this works for you then I can look up for a way to make Java play more nicely with compositing window managers, such as Unity.

UPDATE: Maybe you've fallen back on the Java2D pipeline

If your application fails to use 3D hardware acceleration on Linux, it would fall back to software 3D rendering based on Java2D instead. Java2D has been designed to make use of an X11 extension called DGA, that's no longer supported by major vendors (e.g.: NVIDIA). The result is much CPU scorching and sluggish and unresponsive UI. Try setting sun.java2d.pmoffscreen to false to prevent it from interfering.

If you're on Java 7, try setting -Dsun.java2d.xrender=true instead.

What this isn't

From your description, this appears to be unrelated to Scala or ScalaFX. I'd expect any rendering and/or portability issues to present in the native rendering bits underlying JavaFX or the JRE itself.

nadavwr
  • 1,820
  • 16
  • 20
  • Sadly it didnt work either.. if you try the example above you will see that its like hovering the button instead of the menu... but really thanks for your detailed answer.. – Iraklis May 09 '13 at 16:04