Skip to content

refactor(GuiPanel): replace absolute layout with GridBagLayout for responsive UI#98

Open
AmlanDalai wants to merge 3 commits intosumit3203:masterfrom
AmlanDalai:ui-layout-refactor
Open

refactor(GuiPanel): replace absolute layout with GridBagLayout for responsive UI#98
AmlanDalai wants to merge 3 commits intosumit3203:masterfrom
AmlanDalai:ui-layout-refactor

Conversation

@AmlanDalai
Copy link
Copy Markdown
Contributor

@AmlanDalai AmlanDalai commented Mar 7, 2026

Overview

GuiPanel served as the main navigation dashboard of the Active Segmentation plugin but relied on null layout management with hardcoded pixel coordinates for all nine navigation controls. This approach introduced two significant maintainability concerns that this PR addresses.

Problems Identified

1. Non-responsive layout
Absolute positioning via setLayout(null) and setBounds(x, y, w, h) caused the UI to break on different screen resolutions and prevented the panel from adapting to window resizing.

2. Visual designer incompatibility
Eclipse WindowBuilder could only parse 2 of the 9 components in Design view due to the use of a generic addButton() factory method. This made visual inspection and future UI modifications impractical.

Changes

  • Replaced setLayout(null) with BorderLayout at the panel level and GridBagLayout for the button grid
  • Declared all 9 buttons as explicit named fields (btnSelectFilters, btnFilterVisualization, etc.)
  • Assigned a dedicated GridBagConstraints instance per button
  • Replaced addButton() with styleButton() — separating layout concerns from visual styling
  • Removed System.out.println debug statements from constructor
  • Added Javadoc to all methods and class declaration

Outcome

  • All 9 navigation buttons are now fully visible and editable in Eclipse WindowBuilder Design view
  • Layout responds correctly to window resizing
  • No new compiler errors or warnings introduced

Before vs After — Eclipse WindowBuilder Design View

Before (absolute layout — only 2/9 components parsed):
before-redesign

After (GridBagLayout — all 9 components visible):

after-redesign

- Replace setLayout(null) + setBounds() with BorderLayout/GridBagLayout
- Makes UI responsive to window resizing
- Fixes WindowBuilder parsing: all 9 buttons now visible in Design view
- Extract createButton() helper; remove coordinate parameters
- Remove System.out.println debug statements
- Add full Javadoc to all methods
@AmlanDalai
Copy link
Copy Markdown
Contributor Author

AmlanDalai commented Mar 8, 2026

Note on diff size

The large diff in this PR is due to two structural changes that affected most lines:

  1. Replaced addButton() factory method with named field declarations for each button — WindowBuilder requires components to be declared as named fields to parse them in Design view. This is why each button now has its own declaration instead of being returned from a factory method.

  2. Each button now has its own GridBagConstraints instance (gbc00, gbc01, gbc10 etc.) — sharing a single GBC instance caused "Different parents for double associations" error in WindowBuilder.

The actual logic changes are minimal:

  • setLayout(null) → BorderLayout + GridBagLayout
  • setBounds() coordinates → GridBagConstraints
  • addButton() calls → named JButton fields + styleButton() helper
  • Removed System.out.println debug statements
  • Added Javadoc

All button actions and functionality are identical to the original.

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

Successfully merging this pull request may close these issues.

1 participant