import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import com.sun.javafx.application.PlatformImpl;
import java.awt.FlowLayout;
public class PreferredSize
{
Label l;
JFXPanel fxPanel;
HBox g;
Scene scene;
private PreferredSize()
{
final JFrame f = new JFrame("Test JFXPanel pref size");
f.setSize(800, 600);
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new FlowLayout());
f.add(new JButton("Button 1"));
fxPanel = new JFXPanel();
f.add(fxPanel);
f.add(new JLabel("Label1"));
PlatformImpl.startup(new Runnable()
{
@Override
public void run()
{
g = new HBox();
l = new Label("bla");
g.getChildren().add(l);
scene = new Scene(g);
fxPanel.setScene(scene);
deblockThread();
}
});
blockThread();
f.pack();
f.setVisible(true);
}
public void setText(String text)
{
final String s = text;
Platform.runLater(new Runnable(){
@Override
public void run() {
l.setText(s);
deblockThread();
}
});
blockThread();
System.out.println(g.getPrefWidth(0.0));
System.out.println(g.getPrefHeight(0.0));
System.out.println(g.getBoundsInParent());
}
private synchronized void blockThread()
{
try {
this.wait();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
private synchronized void deblockThread()
{
this.notify();
}
public static void main(String[] args)
{
PreferredSize p = new PreferredSize();
p.setText("huhuhuhu");
}
}
I start a JavaFX-Label in Swing and it gets autosized to the right size. Then i set a new Text with Platform.runLater();. Although the PrefSize-Methods of the label show the right values, the bounds of the label are not updated.
I tried with adding the group to the dirtylayout list, i tried to revalidate it, i tried to repaint the jfxPanel, nothing updated the bounds of the label (control) / jfxPanel.
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import com.sun.javafx.application.PlatformImpl;
import java.awt.FlowLayout;
public class PreferredSize
{
Label l;
JFXPanel fxPanel;
HBox g;
Scene scene;
private PreferredSize()
{
final JFrame f = new JFrame("Test JFXPanel pref size");
f.setSize(800, 600);
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new FlowLayout());
f.add(new JButton("Button 1"));
fxPanel = new JFXPanel();
f.add(fxPanel);
f.add(new JLabel("Label1"));
PlatformImpl.startup(new Runnable()
{
@Override
public void run()
{
g = new HBox();
l = new Label("bla");
g.getChildren().add(l);
scene = new Scene(g);
fxPanel.setScene(scene);
deblockThread();
}
});
blockThread();
f.pack();
f.setVisible(true);
}
public void setText(String text)
{
final String s = text;
Platform.runLater(new Runnable(){
@Override
public void run() {
l.setText(s);
deblockThread();
}
});
blockThread();
System.out.println(g.getPrefWidth(0.0));
System.out.println(g.getPrefHeight(0.0));
System.out.println(g.getBoundsInParent());
}
private synchronized void blockThread()
{
try {
this.wait();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
private synchronized void deblockThread()
{
this.notify();
}
public static void main(String[] args)
{
PreferredSize p = new PreferredSize();
p.setText("huhuhuhu");
}
}
I start a JavaFX-Label in Swing and it gets autosized to the right size. Then i set a new Text with Platform.runLater();. Although the PrefSize-Methods of the label show the right values, the bounds of the label are not updated.
I tried with adding the group to the dirtylayout list, i tried to revalidate it, i tried to repaint the jfxPanel, nothing updated the bounds of the label (control) / jfxPanel.