Strange behavior cobining JidePopupMenu and JavaFX

This is the forum for JIDE Common Layer which is open sourced at https://github.com/jidesoft/jide-oss. Please note, JIDE technical support doesn't monitor this forum as often as other forums. Please consider subscribe for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Moderator: JIDE Support

Forum rules
Community driven forum for open source JIDE Common Layer. JIDE technical support doesn't monitor this forum as often as other forums. If you only use JIDE Common Layer, please consider subscribing for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Strange behavior cobining JidePopupMenu and JavaFX

Postby td84 » Mon Apr 11, 2016 3:14 pm

Hello all,

i'm currently working on a project, that uses a JavaFX TreeView. The TreeView must appear in a popup-window (that is showing if you e.g. click on a Jcombobox).
To create the popup-window i use JidePopupMenu. In the example code below, if you click on the text, the popup appears, showing the Tree.
The problem is, i can open the popup only once. For the second time, it doesn't work.
I open the popup in mouseReleased(). The Tree is initialised in createTextScene().
The TreeView example comes from here:
http://www.javaworld.com/article/207449 ... d-swt.html
http://java-buddy.blogspot.co.at/2012/0 ... ample.html

Can you help me, to get the popup working?
Finally it would be nice, if i could open the popup by clicking on a JideComboBox.
Is it possible to assign the TreeView with a JideComboBox? (I mean, if someone clicks on the arrow at the right, then the TreeView apperas instead of the contents of the JideComboBox).


Thank you,
Daniel



package javaprinter;

import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.layout.StackPane;

import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import com.jidesoft.swing.JidePopupMenu;


public class Javafx
{
static JFXPanel fxPanel = new JFXPanel();
static JidePopupMenu menu = new JidePopupMenu();


private static void initAndShowGUI()
{
// This method is invoked on Swing thread
final JFrame frame = new JFrame("JavaFX / Swing Integrated");
frame.pack();
frame.setSize(150, 100);
frame.setVisible(true);

Platform.runLater(new Runnable()
{
@Override
public void run()
{
initFX(frame);
}
});
}

private static void initFX(JFrame frame)
{
// This method is invoked on JavaFX thread
// Create the TreeView
final Scene scene = createTextScene();
Javafx.fxPanel.setScene(scene);

// add the TreeView to the popup-window
Javafx.menu.add(Javafx.fxPanel);

// create a panel, that will contain a label
JPanel panel = new JPanel();

/* add a label to the panel */
JLabel label = new JLabel("Right click to get a popup");
panel.add(label);
panel.setSize(120, 100);

/* add a mouse listener to handle the right click */
/* a popup-window appears, that shows a JavaFX-TreeView
* with some element. */
frame.addMouseListener(new MouseAdapter(){
@Override
public void mouseReleased(MouseEvent e)
{
if (e.isPopupTrigger()) {
menu.show(e.getComponent(), e.getX(), e.getY());
System.out.println("\nOpening popup-window.\n");
}
}
});

frame.add(panel, BorderLayout.CENTER);
frame.pack();
frame.setSize(150, 100);

System.out.println("\ninit done\n");
}

/**
* Create the content of the TreeView.
* @return a Scene-instance containing the TreeView.
*/
private static Scene createTextScene() {
TreeItem<String> treeItemRoot = new TreeItem<> ("Root");

TreeItem<String> nodeItemA = new TreeItem<>("Item A");
TreeItem<String> nodeItemB = new TreeItem<>("Item B");
TreeItem<String> nodeItemC = new TreeItem<>("Item C");
treeItemRoot.getChildren().addAll(nodeItemA, nodeItemB, nodeItemC);

TreeItem<String> nodeItemA1 = new TreeItem<>("Item A1");
TreeItem<String> nodeItemA2 = new TreeItem<>("Item A2");
TreeItem<String> nodeItemA3 = new TreeItem<>("Item A3");
nodeItemA.getChildren().addAll(nodeItemA1, nodeItemA2, nodeItemA3);

TreeView<String> treeView = new TreeView<>(treeItemRoot);
StackPane root = new StackPane();
root.getChildren().add(treeView);

Scene scene = new Scene(root, 300, 250);
return scene;
}

public static void main(String[] arguments)
{
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
initAndShowGUI();
}
});
}
}
td84
 
Posts: 32
Joined: Tue Dec 08, 2015 4:02 pm

Re: Strange behavior cobining JidePopupMenu and JavaFX

Postby JIDE Support » Mon Apr 11, 2016 3:33 pm

Unfortunately we don't provide any support for JIDE and JavaFX integration at this moment. Most likely it is out of our control anyway.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Strange behavior cobining JidePopupMenu and JavaFX

Postby td84 » Mon Apr 11, 2016 3:44 pm

Ok, it seems, it would be better to implement a simple popup-window (like JidePopupMenu) by myself...
Can you give me some hint, how to do this?

Thank you in advance,
Daniel
td84
 
Posts: 32
Joined: Tue Dec 08, 2015 4:02 pm

Re: Strange behavior cobining JidePopupMenu and JavaFX

Postby JIDE Support » Mon Apr 11, 2016 4:50 pm

I don't know how to do it in JavaFX either. I haven't updated myself with JavaFX for a while :P
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Strange behavior cobining JidePopupMenu and JavaFX

Postby td84 » Mon Apr 11, 2016 11:57 pm

JIDE Support wrote:I don't know how to do it in JavaFX either. I haven't updated myself with JavaFX for a while :P


Ah sorry, forgot to say: the popup window should not be with Javafx. It's ok, with Swing, or Awt ...
How does the class JidePopupMenu realise the popup-window?

Thanx,
Daniel
td84
 
Posts: 32
Joined: Tue Dec 08, 2015 4:02 pm

Re: Strange behavior cobining JidePopupMenu and JavaFX

Postby JIDE Support » Tue Apr 12, 2016 8:17 am

JidePopupMenu is pretty much the same as JPopupMenu. You can look at JPopupMenu source code to see it. Actually JidePopupMenu is also opened source on github under the jide-oss project.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Strange behavior cobining JidePopupMenu and JavaFX

Postby td84 » Tue Apr 12, 2016 8:34 am

Thanx. I realised to combine both together. The problem was, that the TreeView component must be loaded each time from the JavaFX-Thread. Additionally i recreate the popup-window each time the label is clicked.
This should now work.



import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.layout.VBox;

import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import com.jidesoft.swing.JidePopupMenu;


public class Javafx
{
static JFXPanel fxPanel;
static JidePopupMenu menu;
static Scene scene;


public static void initAndShowGUI()
{
// This method is invoked on Swing thread.
// First init the JavaFX-Toolkit by creating a new JFXPanel.
fxPanel = new JFXPanel();

final JFrame frame = new JFrame("JavaFX / Swing Integrated");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setSize(300, 100);
frame.setVisible(true);

setupUI(frame);
}

private static void setupUI(JFrame frame)
{
// create a panel, that will contain a label
JPanel panel = new JPanel();

/* add a label to the panel */
JLabel label = new JLabel("Right click to get a popup");
panel.add(label);
panel.setSize(120, 100);

/* add a mouse listener to handle the right click */
/* a popup-window appears, that shows a JavaFX-TreeView
* with some element inside it. Everything must be called
* from Platform.runLater() */
frame.addMouseListener(new MouseAdapter(){
@Override
public void mouseReleased(final MouseEvent e)
{
if (e.isPopupTrigger()) {
Platform.runLater(new Runnable()
{
@Override
public void run()
{
//Steps to open the popup-window:
//create scene
//setup (eventual recreate) fxpanel
//create and show menu
scene = createTextScene();
fxPanel.removeAll();
fxPanel.setScene(scene);
menu = new MyPopupMenu();
menu.add(fxPanel);
menu.show(e.getComponent(), e.getX(), e.getY());
System.out.format("\n\nOpening popup-window.\n\n");
}
});
}
}
});

frame.add(panel, BorderLayout.CENTER);
frame.pack();
frame.setSize(150, 100);
}

/**
* Create the content of the TreeView.
* @return a Scene-instance containing the TreeView.
*/
private static Scene createTextScene() {
TreeItem<String> treeItemRoot = new TreeItem<> ("Root");

TreeItem<String> nodeItemA = new TreeItem<>("Item A");
TreeItem<String> nodeItemB = new TreeItem<>("Item B");
TreeItem<String> nodeItemC = new TreeItem<>("Item C");
treeItemRoot.getChildren().addAll(nodeItemA, nodeItemB, nodeItemC);

for(int a=1; a<=10; a++) {
TreeItem<String> nodeItemAsub = new TreeItem<>("Item A" + a);
nodeItemA.getChildren().add(nodeItemAsub);
}

TreeView<String> treeView = new TreeView<>(treeItemRoot);

VBox root = new VBox();
root.setAlignment(Pos.CENTER);
root.setStyle("-fx-border-style: solid;"
+ "-fx-border-width: 0;"
+ "-fx-border-color: white");
root.getChildren().add(treeView);

Scene scene = new Scene(root, 120, 250);
return scene;
}

public static void main(String[] arguments)
{
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
Platform.setImplicitExit(false);
initAndShowGUI();
}
});

//Platform.exit();
}
}


class MyPopupMenu extends JidePopupMenu {
protected void paintBorder(Graphics g) {
//JFXPanel has also an own border. Painting the
//border of both looks annoying.
//super.paintBorder(g);
}
}
td84
 
Posts: 32
Joined: Tue Dec 08, 2015 4:02 pm

Re: Strange behavior cobining JidePopupMenu and JavaFX

Postby td84 » Tue Apr 12, 2016 9:42 am

I've just noticed: if i scroll the tree, the popup closes (even if the mouse cursor is inside of the tree).
Can you help me to solve this?

Thanx again,
Daniel
td84
 
Posts: 32
Joined: Tue Dec 08, 2015 4:02 pm

Re: Strange behavior cobining JidePopupMenu and JavaFX

Postby JIDE Support » Tue Apr 12, 2016 9:44 am

It should close. That's what JPopupMenu do - every mouse click outside will dismiss the popup menu.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Strange behavior cobining JidePopupMenu and JavaFX

Postby td84 » Tue Apr 12, 2016 12:38 pm

But in my case the mouse is inside the popup menu and i don't click, but scroll and the popup closes.
A click inside the popup leaves the window open; that's correct.
td84
 
Posts: 32
Joined: Tue Dec 08, 2015 4:02 pm

Re: Strange behavior cobining JidePopupMenu and JavaFX

Postby td84 » Wed Apr 13, 2016 9:26 am

Could the mouse scroll event be catched in the popup menu?
td84
 
Posts: 32
Joined: Tue Dec 08, 2015 4:02 pm

Re: Strange behavior cobining JidePopupMenu and JavaFX

Postby JIDE Support » Wed Apr 13, 2016 9:40 am

Probably possible. But this really has nothing to do with JIDE. You should look at JPopupMenu source code and try to figure out a solution.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Strange behavior cobining JidePopupMenu and JavaFX

Postby td84 » Thu Apr 14, 2016 12:47 am

Yes, it seems i can't scroll only if i add a JFXPanel to JidePopupMenu.
I added a JPanel, and it worked well.
td84
 
Posts: 32
Joined: Tue Dec 08, 2015 4:02 pm

Re: Strange behavior cobining JidePopupMenu and JavaFX

Postby JIDE Support » Thu Apr 14, 2016 7:54 am

That's why I don't like the idea of JavaFX integration with Swing. Different designs, different UIs, different architectures, thus results in a patchy product.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am


Return to JIDE Common Layer Open Source Project Discussion (Community Driven)

Who is online

Users browsing this forum: Google [Bot] and 8 guests

cron