Open Paradnor opened 2 months ago
You should really provide more information. Screen shots, a simple code example, ...
As a start,
Here the normal situation (Either with "Screen only" or "Extended" mode)
Here the situation when I'm in "Duplicate screen" mode
I'll try to produce a sample code reproducing the issue after my working day :)
Hello !
Sorry for the late reply. I was busier than expected.
Here is a simple code example :
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.stage.Stage;
import org.tbee.javafx.scene.layout.MigPane;
public class Sample extends Application {
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("MigLayout JavaFX Example");
// Creating a MigPane with column and row constraints
MigPane migPane = new MigPane("wrap 1", "[grow]", "[][grow][]");
// Adding components to the MigPane
migPane.add(new Label("Top Section"), "cell 0 0, wrap");
migPane.add(new Button("Middle Section"), "cell 0 1, grow, wrap");
migPane.add(new Label("Bottom Section"), "cell 0 2");
// Setting the scene
Scene scene = new Scene(migPane, 400, 300);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
To explain the problem more clearly, all is fine while I stay in "First Screen only" or "Extend" display mode from Windows. As in the following picture :
However, when I set my display mode to "Duplicate", the layout seems to break somehow :
It is like the layout recomputes its size and its components size as well. However, when I duplicate my screen I think it should keep the "First Screen" resolution and so shouldn't recompute them.
Any help or explanation would be appreciated.
Thanks :)
PS : I forgot to tell, it is on Javafx library 11.3 with OpenJDK 21.0.2
Just to check if this is a MigPane or MigLayout issue, what happens with the swing equivalent?
import net.miginfocom.swing.MigLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import java.awt.Dimension;
import java.lang.reflect.InvocationTargetException;
public class TestSwing {
public static void main(String[] args) throws InterruptedException, InvocationTargetException {
SwingUtilities.invokeAndWait(() -> {
MigLayout layout = new MigLayout("wrap 1", "[grow]", "[][grow][]");
JPanel pane = new JPanel();
pane.setLayout(layout);
pane.add(new JLabel("Top Section"), "cell 0 0, wrap");
pane.add(new JButton("Middle Section"), "cell 0 1, grow, wrap");
pane.add(new JLabel("Bottom Section"), "cell 0 2");
JFrame frame = new JFrame("Test");
frame.setContentPane(pane);
frame.setSize(new Dimension(600, 400));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
});
}
}
The swing equivalent is stable :)
Any update about this issue ? :)
Back from vacation. I've been able to reproduce your problem. Weird. I would expect problems in extend mode, but not here. Will have to play with that a bit.
Okay, I've started to take a look. My first question is: if you're doing cell based layout, why are you using the "wrap" constraint? Wrap is intended for flow based layouts and wraps to a new row. If you're specifying the cell positions, wrap does not make sense?
I found the cause, don't know a solution yet.
In MigPane the screen's DPI is used to convert logical sizes to actual pixels, in duplicate mode JavaFX reports the DPI as 0, which causes a.o. the gap calculations to result in 0 gaps. In extended mode each screen has it's own DPI (in my setup 93 and 113) and the logic works correctly.
MigLayout of course bases itself on the info JavaFX provides, so I don't know how to fix that. Using a default DPI of 96, in case 0 is returned, seems not correct either, but apparently that is often used .
Okay, I've started to take a look. My first question is: if you're doing cell based layout, why are you using the "wrap" constraint? Wrap is intended for flow based layouts and wraps to a new row. If you're specifying the cell positions, wrap does not make sense?
To be honest it is probably my misunderstanding of the library. It was the first time I use it ! :) From your comment, I guess it makes no sense indeed ! :)
I found the cause, don't know a solution yet.
In MigPane the screen's DPI is used to convert logical sizes to actual pixels, in duplicate mode JavaFX reports the DPI as 0, which causes a.o. the gap calculations to result in 0 gaps. In extended mode each screen has it's own DPI (in my setup 93 and 113) and the logic works correctly.
MigLayout of course bases itself on the info JavaFX provides, so I don't know how to fix that. Using a default DPI of 96 in case 0 is returned seems not correct either, but apparently is the often the default value.
Thank you very much for your investigations !
Using 0 for the dpi seems more wrong than a decent default, so I've released MigLayout 11.4.1. Give that a try if you will.
Thank you very much. I just gave it a try and the behavior is better than previously.
Hello and thank you very much for the library.
Lately I did a dev with it to place seats over the layout.
However, when my laptop is in "Duplicate Screen" mode, all the layout is broken. Those seats go on the top left corner.
Is there any way to fix that ?
Many thanks