Skip to content

Commit

Permalink
#1936 fix scrolling of training table (#1945)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsbrenk authored Nov 20, 2023
1 parent f6dff49 commit b1c920b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/main/java/module/training/ui/OutputPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Point;
import java.awt.event.AdjustmentListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
Expand Down Expand Up @@ -110,8 +111,6 @@ private void importMatches() {
private void addListeners() {
var playerIdColumnIndex = this.outputTable.getColumnCount()-1;
this.outputTable.getSelectionModel().addListSelectionListener(new PlayerSelectionListener(this.model, this.outputTable, playerIdColumnIndex));


this.outputTable.getSelectionModel().addListSelectionListener(e -> {
var index = outputTable.getSelectedRow();
fixedOutputTable.getSelectionModel().setSelectionInterval(index, index);
Expand All @@ -121,9 +120,7 @@ private void addListeners() {
outputTable.getSelectionModel().setSelectionInterval(index, index);
});


this.importButton.addActionListener(arg0 -> importMatches());

this.calculateButton.addActionListener(arg0 -> {
// recalcSubskills() causes UI update via RefreshManager, so no
// need to update UI ourself
Expand All @@ -147,7 +144,6 @@ public void mouseReleased(MouseEvent e) {
}
}
});

}

private void selectPlayerFromModel() {
Expand Down Expand Up @@ -214,6 +210,7 @@ private void initComponents() {

outputTable.setAutoResizeMode(0);
outputTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
fixedOutputTable.setPreferredScrollableViewportSize(new Dimension(150, 70));
outputTable.setAutoCreateRowSorter(true);
fixedOutputTable.setAutoCreateRowSorter(true);

Expand All @@ -226,16 +223,26 @@ private void initComponents() {
sortKeys.add(new RowSorter.SortKey(columnIndexToSort, SortOrder.DESCENDING));
sorter.setSortKeys(sortKeys);
sorter.sort();

var scrollPane = new JScrollPane(outputTable);
Dimension fixedSize = fixedOutputTable.getPreferredSize();
JViewport viewport = new JViewport();
viewport.setView(fixedOutputTable);
viewport.setPreferredSize(fixedSize);
viewport.setMaximumSize(fixedSize);
scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, fixedOutputTable.getTableHeader());
scrollPane.setRowHeaderView(viewport);
add(scrollPane, BorderLayout.CENTER);
var fixedScrollPane = new JScrollPane(fixedOutputTable);
var bar = fixedScrollPane.getVerticalScrollBar();
var bar2 = scrollPane.getVerticalScrollBar();
bar.setPreferredSize(new Dimension(0, 0));
// Synchronize vertical scrolling
AdjustmentListener adjustmentListener = e -> {
if (e.getSource() == bar2) {
bar.setValue(e.getValue());
} else {
bar2.setValue(e.getValue());
}
};
bar.addAdjustmentListener(adjustmentListener);
bar2.addAdjustmentListener(adjustmentListener);

JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false);
splitPane.setLeftComponent(fixedScrollPane);
splitPane.setRightComponent(scrollPane);
add(splitPane, BorderLayout.CENTER);

JPanel buttonPanel = new JPanel(new GridBagLayout());

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* fix transfer scout's copy and paste of own players (#1897)

### Training
* fix scrolling of training table (#1936)

### League

Expand Down

0 comments on commit b1c920b

Please sign in to comment.