From a2dc165944d25500ad0b314b8e0025b632d42e26 Mon Sep 17 00:00:00 2001 From: Radek Davidek Date: Thu, 19 Feb 2026 10:12:45 +0100 Subject: [PATCH] panel divider ron resize fixed --- src/main/java/cz/kamma/kfmanager/MainApp.java | 2 +- .../cz/kamma/kfmanager/ui/MainWindow.java | 36 +++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/main/java/cz/kamma/kfmanager/MainApp.java b/src/main/java/cz/kamma/kfmanager/MainApp.java index c71c134..75ddb73 100644 --- a/src/main/java/cz/kamma/kfmanager/MainApp.java +++ b/src/main/java/cz/kamma/kfmanager/MainApp.java @@ -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 diff --git a/src/main/java/cz/kamma/kfmanager/ui/MainWindow.java b/src/main/java/cz/kamma/kfmanager/ui/MainWindow.java index d373bdd..9197582 100644 --- a/src/main/java/cz/kamma/kfmanager/ui/MainWindow.java +++ b/src/main/java/cz/kamma/kfmanager/ui/MainWindow.java @@ -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); + } } });