GithubHelp home page GithubHelp logo

Does sizegroup work in javaFX? about miglayout HOT 12 CLOSED

MrKuip avatar MrKuip commented on September 15, 2024
Does sizegroup work in javaFX?

from miglayout.

Comments (12)

MrKuip avatar MrKuip commented on September 15, 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

from miglayout.

tbee avatar tbee commented on September 15, 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.

from miglayout.

MrKuip avatar MrKuip commented on September 15, 2024

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

from miglayout.

tbee avatar tbee commented on September 15, 2024

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

from miglayout.

tbee avatar tbee commented on September 15, 2024

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

from miglayout.

tbee avatar tbee commented on September 15, 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.

from miglayout.

MrKuip avatar MrKuip commented on September 15, 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?

from miglayout.

tbee avatar tbee commented on September 15, 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.

from miglayout.

tbee avatar tbee commented on September 15, 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.

from miglayout.

MrKuip avatar MrKuip commented on September 15, 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?

from miglayout.

tbee avatar tbee commented on September 15, 2024

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

from miglayout.

tbee avatar tbee commented on September 15, 2024

I've released 11.4 with the invalidateGrid change

from miglayout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.