Skip to content

Commit

Permalink
Fix Filter Panel display when going to/from empty panel
Browse files Browse the repository at this point in the history
The JPanel's default FlowLayout adds 5px paddings on top and bottom.
Without any filter buttons it is of no concern as the panel with(out)
buttons has a desired height of 0, so it is stretched out to the size of
the container. When the filter button appears, these paddings are
applied and this caused the FilterPanel to become 10px taller.

The fix is to remove the default paddings from the inner JPanel.
Instead, some paddings were added to the FilterPanel itself to achieve
a more pleasant look.

Additionally, a "revalidate()+repaint()" spell is now used when the
filter is added. Without this, the change in height is not propagated
to the FilterPanel (thought there is no more change in height).

Issue: #218
  • Loading branch information
mlopatkin committed Jan 13, 2022
1 parent 6ecf056 commit c35c194
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public void onFilterAdded(PanelFilterView newFilter) {
buttonByFilter.put(newFilter, button);
content.add(button);
menuHandler.addPopup(button);
validate();
revalidate();
repaint();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import javax.swing.JViewport;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;

/**
* FilterPanel implementation. Generated class from WindowBuilder editor.
Expand All @@ -48,6 +49,7 @@ class FilterPanelUi extends JPanel {
protected final JViewport contentViewport;

FilterPanelUi() {
setBorder(new EmptyBorder(5, 5, 5, 5));
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
setBackground(UIManager.getColor("ToolBar.background"));

Expand All @@ -68,9 +70,9 @@ class FilterPanelUi extends JPanel {
add(Box.createRigidArea(new Dimension(SEPARATOR_WIDTH, SEPARATOR_HEIGHT)));

content = new JPanel();
content.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0));
content.setBackground(UIManager.getColor("ToolBar.background"));
content.setBorder(UiHelper.NO_BORDER);
((FlowLayout) content.getLayout()).setAlignment(FlowLayout.LEFT);
JScrollPane scrollPane =
new JScrollPane(content, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setBorder(UiHelper.NO_BORDER);
Expand Down

0 comments on commit c35c194

Please sign in to comment.