Skip to content

Commit

Permalink
Fix lack of scrollbars in Advantage editor
Browse files Browse the repository at this point in the history
  • Loading branch information
richardwilkes committed Aug 2, 2020
1 parent 5fc0897 commit 4ccdf2e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.trollworks.gcs.weapon.WeaponStats;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
Expand All @@ -45,7 +44,6 @@
import java.util.List;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
Expand Down Expand Up @@ -245,8 +243,8 @@ public AdvantageEditor(Advantage advantage) {
panel = embedEditor(mFeatures);
mTabPanel.addTab(panel.getName(), panel);
mTabPanel.addTab(mModifiers.getName(), mModifiers);
mTabPanel.addTab(mMeleeWeapons.getName(), wrapInScroller(mMeleeWeapons));
mTabPanel.addTab(mRangedWeapons.getName(), wrapInScroller(mRangedWeapons));
mTabPanel.addTab(mMeleeWeapons.getName(), new JScrollPane(mMeleeWeapons));
mTabPanel.addTab(mRangedWeapons.getName(), new JScrollPane(mRangedWeapons));

if (!mIsEditable) {
UIUtilities.disableControls(mMeleeWeapons);
Expand All @@ -268,15 +266,7 @@ public AdvantageEditor(Advantage advantage) {

UIUtilities.selectTab(mTabPanel, getLastTabName());

add(mTabPanel, new PrecisionLayoutData().setHorizontalSpan(3).setFillAlignment().setGrabSpace(true));
}

private JScrollPane wrapInScroller(JComponent comp) {
JScrollPane scroller = new JScrollPane(comp);
// Unclear why this next line is needed. Failure to include it, however, results in the
// scroller being sized larger than the space available.
scroller.setPreferredSize(new Dimension(10, 10));
return scroller;
add(mTabPanel, new PrecisionLayoutData().setHorizontalSpan(3).setFillAlignment().setGrabSpace(true).setMinimumHeight(32));
}

private JScrollPane createUserDescEditor() {
Expand All @@ -300,7 +290,7 @@ public void changedUpdate(DocumentEvent event) {
mUserDesc = editor.getText();
}
});
return wrapInScroller(editor);
return new JScrollPane(editor);
}

private JCheckBox createTypeCheckBox(boolean selected, String tooltip) {
Expand All @@ -323,13 +313,12 @@ public void mouseClicked(MouseEvent event) {
}

private JScrollPane embedEditor(JPanel editor) {
JScrollPane scrollPanel = new JScrollPane(editor);
scrollPanel.setMinimumSize(new Dimension(500, 120));
scrollPanel.setName(editor.toString());
JScrollPane scroller = new JScrollPane(editor);
scroller.setName(editor.toString());
if (!mIsEditable) {
UIUtilities.disableControls(editor);
}
return scrollPanel;
return scroller;
}

private EditorField createField(String text, String prototype, String tooltip) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,10 @@ private void handleOutline(String cmd) {
protected abstract void addColumns(Outline outline);

private Component createOutline(List<? extends Modifier> readOnlyModifiers, List<? extends Modifier> modifiers) {
JScrollPane scroller;
OutlineModel model;

mAddButton = new IconButton(Images.ADD, I18n.Text("Add a modifier"), () -> addModifier());

mOutline = new ModifierOutline();
model = mOutline.getModel();
OutlineModel model = mOutline.getModel();
addColumns(mOutline);

if (readOnlyModifiers != null) {
Expand All @@ -92,7 +89,7 @@ private Component createOutline(List<? extends Modifier> readOnlyModifiers, List
}
mOutline.addActionListener(this);

scroller = new JScrollPane(mOutline, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
JScrollPane scroller = new JScrollPane(mOutline, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scroller.setColumnHeaderView(mOutline.getHeaderPanel());
scroller.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, mAddButton);
return scroller;
Expand Down

0 comments on commit 4ccdf2e

Please sign in to comment.