JFXPanel ignores size change of root node
Werner Lehmann
lehmann at media-interactive.de
Fri Dec 14 10:52:56 PST 2012
Hi,
as far as I know JFXPanel is supposed to be sized according to its
content (also stated in RT-13758). This does not seem to work when the
content's size changes later: the jfxpanel is not resized along.
Hopefully I am missing something. The test code below creates a Swing
flowlayout with a button, a jfxpanel, and a label:
http://s16.postimage.org/6nfil2myt/jfxpanel_width_160px.png
When clicking the button, the rectangle inside the fxpanel is resized
from 160px to 120px width. The jfxpanel itself does not seem to be resized:
http://s16.postimage.org/p1q1p1z9h/jfxpanel_width_120px.png
It also does not work to increase the rectangle width - the jfxpanel
width does not change. In my non-test application I have tried to remove
and add the jfxpanel but that only works sometimes and is not exactly
elegant. Any ideas?
Rgds
Werner
> public class JFXPanelResizeTest
> {
> public static void main(String[] args)
> {
> SwingUtilities.invokeLater(new Runnable() {
> @Override public void run() { initAndShowGUI(); }
> });
> }
>
> private static void initAndShowGUI()
> {
> final JFrame f = new JFrame("Test JFXPanel resize");
> f.setSize(600, 200);
> f.setLocationRelativeTo(null);
> f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
> f.setLayout(new FlowLayout());
> final MyJFXPanel fxPanel = new MyJFXPanel();
> JButton button = new JButton("Toggle Rectangel Width");
> button.addActionListener(new ActionListener() {
> @Override public void actionPerformed(ActionEvent paramActionEvent) { fxPanel.toggle(); }
> });
> f.add(button);
> f.add(fxPanel);
> f.add(new JLabel("Label1"));
> f.setVisible(true);
> }
>
> private static class MyJFXPanel extends JFXPanel
> {
> private final Rectangle r = new Rectangle(160, 120);
>
> public MyJFXPanel()
> {
> Platform.runLater(new Runnable() {
> @Override public void run() { setScene(new Scene(new Group(r))); }
> });
> }
>
> // Toggle rectangle width 120px / 160px.
> public void toggle()
> {
> Platform.runLater(new Runnable() {
> @Override public void run() { r.setWidth(r.getWidth() == 160 ? 120 : 160); }
> });
> }
> }
> }
More information about the openjfx-dev
mailing list