Skip to content

Commit 205c8aa

Browse files
authored
Merge pull request #5726 from kwvanderlinde/bugfix/5725-bar-scrolling
Improve scrolling for states and bars
2 parents 1493372 + 46e2b2b commit 205c8aa

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/main/java/net/rptools/maptool/client/ui/token/dialog/edit/EditTokenDialog.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ public void initStatSheetComboBoxes() {
173173
});
174174
}
175175

176+
public void initStatesAndBarsPanel() {
177+
var test = (JScrollPane) getComponent("statesAndBarsScrollPane");
178+
// This number is a bit arbitrary, but importantly it is much bigger than the default of 1 pixel
179+
// but still likely to be smaller than a single bar's height.
180+
test.getVerticalScrollBar().setUnitIncrement(20);
181+
}
182+
176183
public void initTerrainModifierOperationComboBox() {
177184
getTerrainModifierOperationComboBox()
178185
.setModel(new DefaultComboBoxModel<>(TerrainModifierOperation.values()));
@@ -1058,7 +1065,7 @@ private void updateStatesPanel() {
10581065

10591066
/* Add sliders to the bar panel */
10601067
var barsPanel = getBarsPanel();
1061-
barsPanel.setLayout(new MigLayout("wrap 1", "[fill,grow]"));
1068+
barsPanel.setLayout(new MigLayout("wrap 2,gapx 5%", "[fill,grow][fill,grow]"));
10621069
barsPanel.removeAll();
10631070
if (MapTool.getCampaign().getTokenBarsMap().isEmpty()) {
10641071
barsPanel.setVisible(false);
@@ -1067,20 +1074,22 @@ private void updateStatesPanel() {
10671074
for (BarTokenOverlay bar : MapTool.getCampaign().getTokenBarsMap().values()) {
10681075
JSlider slider = new JSlider(0, 100);
10691076
JCheckBox hide = new JCheckBox(I18N.getString("EditTokenDialog.checkbox.state.hide"));
1070-
hide.putClientProperty("JSlider", slider);
10711077
hide.addChangeListener(
10721078
e -> {
1073-
JSlider js = (JSlider) ((JCheckBox) e.getSource()).getClientProperty("JSlider");
1074-
js.setEnabled(!((JCheckBox) e.getSource()).isSelected());
1079+
slider.setEnabled(!((JCheckBox) e.getSource()).isSelected());
10751080
});
10761081
slider.setName(bar.getName());
10771082
slider.setPaintLabels(true);
10781083
slider.setPaintTicks(true);
1079-
slider.setMajorTickSpacing(20);
1080-
slider.createStandardLabels(20);
1081-
slider.setMajorTickSpacing(10);
1084+
slider.setMajorTickSpacing(25);
1085+
slider.setLabelTable(slider.createStandardLabels(50));
1086+
slider.setMinorTickSpacing(5);
1087+
1088+
// Sliders by default have a fixed preferred size. Overriding it to zero will instead let
1089+
// MigLayout grow the slider to fill the space.
1090+
slider.setPreferredSize(new Dimension(0, 0));
10821091

1083-
JPanel tokenbarPanel = new JPanel(new MigLayout("wrap 2", "[fill,grow][fill,grow]"));
1092+
JPanel tokenbarPanel = new JPanel(new MigLayout("wrap 2", "[fill][fill,grow]"));
10841093
tokenbarPanel.add(new JLabel(bar.getName() + ":"));
10851094
tokenbarPanel.add(slider, "span 1 2 align right");
10861095
tokenbarPanel.add(hide);
@@ -1992,7 +2001,7 @@ public MTMultilineStringPopupPanel(String paramString) {
19922001
log.error("Error while loading multiline property editor theme", e);
19932002
}
19942003
JScrollPane localJScrollPane = new RTextScrollPane(j);
1995-
localJScrollPane.setVerticalScrollBarPolicy(22);
2004+
localJScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
19962005
localJScrollPane.setAutoscrolls(true);
19972006
localJScrollPane.setPreferredSize(new Dimension(300, 200));
19982007
setBorder(BorderFactory.createEmptyBorder(10, 5, 5, 5));

src/main/java/net/rptools/maptool/client/ui/token/dialog/edit/TokenPropertiesDialog.form

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,6 @@
552552
<constraints>
553553
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
554554
</constraints>
555-
<properties/>
556555
</component>
557556
</children>
558557
</grid>
@@ -1113,6 +1112,7 @@
11131112
</constraints>
11141113
<properties>
11151114
<horizontalScrollBarPolicy value="31"/>
1115+
<name value="statesAndBarsScrollPane"/>
11161116
</properties>
11171117
<border type="empty"/>
11181118
<children>

0 commit comments

Comments
 (0)