JFXPanel ignores size change of root node
Artem Ananiev
artem.ananiev at oracle.com
Mon Dec 17 03:09:57 PST 2012
Hi, Werner,
On 12/14/2012 10:52 PM, Werner Lehmann wrote:
> 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
this is true... to some extent. JFXPanel's preferred size is set only
once, when a scene is attached to it. If you change scene content after
that, scene/stage size is not suppose to change.
Just imagine the following scenario. Create a regular FX Stage and put a
120x120 button inside. Then show the stage. Then set an action listener
to the button, so it changes the button size to 160x120. Will the stage
size change, when the button is clicked?
> 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?
Could you try to leave JFXPanel as is, but set its scene to null and
back to your scene, please? I don't say it's the way it's supposed to
work, just an idea for workaround.
In general, updating JFXPanel's preferred size upon FX scene
size/content changes looks like a valid request. It's not a pure
JFXPanel feature, though: we need to have a notification from Scene to
know that the window size should be updated.
Thanks,
Artem
> 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