Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does sizegroup work in javaFX? #106

Closed
MrKuip opened this issue Jun 3, 2024 · 12 comments
Closed

Does sizegroup work in javaFX? #106

MrKuip opened this issue Jun 3, 2024 · 12 comments

Comments

@MrKuip
Copy link

MrKuip commented Jun 3, 2024

The following code doesn't show the buttons with an equal size.
Does sizegroup work in javaFX?

package org.kku.jdiskusage.main;

import org.tbee.javafx.scene.layout.MigPane;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;

public class Test
  extends Application
{
  @Override
  public void start(Stage stage)
  {
    MigPane pane;
    Scene scene;

    pane = new MigPane();
    pane.add(new Button("hello"), "sizegroup test");
    pane.add(new Button("Long text"), "sizegroup test");

    scene = new Scene(pane);
    stage.setScene(scene);

    stage.show();
  }

  public static void main(String[] args)
  {
    launch();
  }
}

This is the result:
image

@MrKuip
Copy link
Author

MrKuip commented Jun 3, 2024

The same layout works perfect when used with swing


package org.kku.jdiskusage.main;

import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import net.miginfocom.swing.MigLayout;

public class Test
{
  public Test()
  {
    start();
  }

  public void start()
  {
    JPanel pane;
    MigLayout layout;
    JFrame frame;

    layout = new MigLayout();
    pane = new JPanel();
    pane.setLayout(layout);
    pane.add("sizegroup test", new JButton("Text"));
    pane.add("sizegroup test", new JButton("Long text"));

    frame = new JFrame("Test");
    frame.setContentPane(pane);
    frame.setSize(new Dimension(600, 400));
    frame.show();
  }

  public static void main(String[] args)
  {
    new Test();
  }
}

image

@MrKuip MrKuip changed the title Does sizegroup work? Does sizegroup work in javaFX? Jun 3, 2024
@tbee
Copy link
Collaborator

tbee commented Jun 6, 2024

Apparently not would be the answer. Which is weird, because both layouts share the same 'engine'. I am curious what the calculated sized is in each scenario.

@MrKuip
Copy link
Author

MrKuip commented Jun 7, 2024

Do you want me to debug and report the calculated sizes?

@tbee
Copy link
Collaborator

tbee commented Jun 7, 2024

No. I need some time to look into it, but busy schedule.

@tbee
Copy link
Collaborator

tbee commented Jun 15, 2024

Sigh, ever since the project was modularized, I can't get it to run in IntelliJ. Working on it.

@tbee
Copy link
Collaborator

tbee commented Jun 30, 2024

Update. So, have it setup like a kludge, but I was able to figure out what goes wrong, but I'm not sure what the fix would be.

What happens is that during initial setup the max value in the sizegroup is correctly determined, and the component wrappers get their sizes set accordingly (grid.setForcedSizes). Then the container gets its size set. In MigPane (so JavaFX) this calls invalidateContainerSize, which causes the sizes of the components to be redetermined, undoing the sizegroup.

The question now is: why is the invalidateContainerSize necessary? Or (since MigLayout's algorithm is Mikael's, not mine): why does the invalidate also not apply the sizegroup logic again?

I suspect the invalidateContainerSize has to do with resizing the scene/stage (it has been too long), so maybe that is the wrong place, or there is no alternative place to react to that event.

@MrKuip
Copy link
Author

MrKuip commented Jun 30, 2024

As far as I can see the only module that calls invalidateContainerSize is the javafx module.
So I removed the calls to invalidateContainerSize in javafx MigPane and I get the correct layout.
Was invalidateContainerSize specifically added to Grid.java for JavaFX?

@tbee
Copy link
Collaborator

tbee commented Jun 30, 2024

I don't know; that code was added by Mikael in 2016. He will have had a reason for it. I'll try to run the tests with the change in and see how they fare.

@tbee
Copy link
Collaborator

tbee commented Jul 2, 2024

What also works is replacing invalidateContainerSize with invalidateGrid. That seems to make more sense; in 2018 I've added some caching logic where _grid is created less often. That is probably the cause, so basically that should be reverted. Or improved to include the sizegroup bounds, so also run the grid constructor code.

After a few tries I think I'm going for the invalidateGrid change.

@MrKuip
Copy link
Author

MrKuip commented Jul 2, 2024

I think you are right. invalidateContainerSize was invented to solve a bug. Just removing is not helpful

Did you also notice that lots of javafx test fail?
The tests expect a layout that is pixel perfect.
But if for instance the font is changed in the jdk then the tests will fail. Maybe that is the cause?

@tbee
Copy link
Collaborator

tbee commented Jul 2, 2024

MigLayout uses different values on different OSes, so the test were written on/for Windows.

@tbee
Copy link
Collaborator

tbee commented Jul 4, 2024

I've released 11.4 with the invalidateGrid change

@tbee tbee closed this as completed Jul 4, 2024
tbee added a commit that referenced this issue Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants