panel divider ron resize fixed

This commit is contained in:
Radek Davidek 2026-02-19 10:12:45 +01:00
parent 8a86dda3dc
commit a2dc165944
2 changed files with 30 additions and 8 deletions

View File

@ -15,7 +15,7 @@ import java.io.InputStreamReader;
*/
public class MainApp {
public static final String APP_VERSION = "1.1.5";
public static final String APP_VERSION = "1.1.6";
public enum OS {
WINDOWS, LINUX, MACOS, UNKNOWN

View File

@ -34,6 +34,7 @@ public class MainWindow extends JFrame {
private JLabel cmdLabel;
private AppConfig config;
private Timer autoRefreshTimer;
private boolean isWindowResizing = false;
public MainWindow() {
super("KF Manager v" + MainApp.APP_VERSION + " (" + MainApp.CURRENT_OS + ")");
@ -109,6 +110,8 @@ public class MainWindow extends JFrame {
// Panel containing the two file panels with resizable divider
mainPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
mainPanel.setContinuousLayout(true);
// Initially set resize weight based on saved proportion to maintain it during first layout/resize
mainPanel.setResizeWeight(config.getDividerPosition());
// Disable default JSplitPane F6/Shift+F6 bindings which interfere with our Move/Rename actions
mainPanel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0), "none");
@ -162,6 +165,8 @@ public class MainWindow extends JFrame {
double savedPosition = config.getDividerPosition();
if (savedPosition >= 0.0 && savedPosition <= 1.0) {
mainPanel.setDividerLocation(savedPosition);
// Dynamically update resizeWeight to maintain current proportion during future window resizes
mainPanel.setResizeWeight(savedPosition);
} else {
// If it was saved as absolute pixels (historically), use as int
mainPanel.setDividerLocation((int) savedPosition);
@ -174,12 +179,18 @@ public class MainWindow extends JFrame {
// Listen for divider position changes to update saved position and tooltip
mainPanel.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, e -> {
int location = mainPanel.getDividerLocation();
int width = mainPanel.getWidth();
int dividerSize = mainPanel.getDividerSize();
if (width > dividerSize) {
double proportionalPosition = (double) location / (width - dividerSize);
config.setDividerPosition(proportionalPosition);
// Only update saved position and resizeWeight if the change was NOT caused by a window resize.
// This prevents the ratio from "drifting" when panels hit their minimum sizes during window resize.
if (!isWindowResizing) {
int location = mainPanel.getDividerLocation();
int width = mainPanel.getWidth();
int dividerSize = mainPanel.getDividerSize();
if (width > dividerSize) {
double proportionalPosition = (double) location / (width - dividerSize);
config.setDividerPosition(proportionalPosition);
// Dynamically update resizeWeight to maintain current proportion during future window resizes
mainPanel.setResizeWeight(proportionalPosition);
}
}
updateDividerTooltip(mainPanel);
@ -195,7 +206,18 @@ public class MainWindow extends JFrame {
mainPanel.addComponentListener(new java.awt.event.ComponentAdapter() {
@Override
public void componentResized(java.awt.event.ComponentEvent e) {
updateDividerTooltip(mainPanel);
isWindowResizing = true;
try {
// Keep proportional divider position when window or splitpane is resized
double proportionalPosition = config.getDividerPosition();
if (proportionalPosition >= 0.0 && proportionalPosition <= 1.0) {
mainPanel.setDividerLocation(proportionalPosition);
}
updateDividerTooltip(mainPanel);
} finally {
// Reset flag after layout has likely happened
SwingUtilities.invokeLater(() -> isWindowResizing = false);
}
}
});