FlatSmoothScrollingTest: allow enabling/disabling smooth scrolling with Alt+S without moving focus to checkbox; removed unused tree model

This commit is contained in:
Karl Tauber
2020-08-09 21:32:42 +02:00
parent 7a582c2d1f
commit 522ebb6fa3
2 changed files with 16 additions and 23 deletions

View File

@@ -44,6 +44,15 @@ public class FlatSmoothScrollingTest
FlatSmoothScrollingTest() {
initComponents();
// allow enabling/disabling smooth scrolling with Alt+S without moving focus to checkbox
registerKeyboardAction(
e -> {
smoothScrollingCheckBox.setSelected( !smoothScrollingCheckBox.isSelected() );
smoothScrollingChanged();
},
KeyStroke.getKeyStroke( "alt " + (char) smoothScrollingCheckBox.getMnemonic() ),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
listScrollPane.getVerticalScrollBar().addAdjustmentListener( new AdjustmentHandler( "list vert" ) );
listScrollPane.getHorizontalScrollBar().addAdjustmentListener( new AdjustmentHandler( "list horz" ) );
@@ -119,6 +128,10 @@ public class FlatSmoothScrollingTest
textArea.setText( text );
textPane.setText( text );
editorPane.setText( text );
textArea.select( 0, 0 );
textPane.select( 0, 0 );
editorPane.select( 0, 0 );
}
private void smoothScrollingChanged() {
@@ -165,6 +178,7 @@ public class FlatSmoothScrollingTest
//---- smoothScrollingCheckBox ----
smoothScrollingCheckBox.setText("Smooth scrolling");
smoothScrollingCheckBox.setSelected(true);
smoothScrollingCheckBox.setMnemonic('S');
smoothScrollingCheckBox.addActionListener(e -> smoothScrollingChanged());
add(smoothScrollingCheckBox, "cell 0 0,alignx left,growx 0");
@@ -188,16 +202,6 @@ public class FlatSmoothScrollingTest
//======== treeScrollPane ========
{
//---- tree ----
tree.setModel(new DefaultTreeModel(
new DefaultMutableTreeNode("root") {
{
add(new DefaultMutableTreeNode("a"));
add(new DefaultMutableTreeNode("b"));
add(new DefaultMutableTreeNode("c"));
}
}));
treeScrollPane.setViewportView(tree);
}
add(treeScrollPane, "cell 1 2");
@@ -306,7 +310,7 @@ public class FlatSmoothScrollingTest
@Override
public Point getViewPosition() {
Point viewPosition = super.getViewPosition();
System.out.println( " viewPosition " + viewPosition.x + "," + viewPosition.y );
// System.out.println( " viewPosition " + viewPosition.x + "," + viewPosition.y );
return viewPosition;
}
};

View File

@@ -13,6 +13,7 @@ new FormModel {
name: "smoothScrollingCheckBox"
"text": "Smooth scrolling"
"selected": true
"mnemonic": 83
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "smoothScrollingChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 0,alignx left,growx 0"
@@ -51,18 +52,6 @@ new FormModel {
name: "treeScrollPane"
add( new FormComponent( "javax.swing.JTree" ) {
name: "tree"
"model": new javax.swing.tree.DefaultTreeModel( new javax.swing.tree.DefaultMutableTreeNode {
userObject: "root"
add( new javax.swing.tree.DefaultMutableTreeNode {
userObject: "a"
} )
add( new javax.swing.tree.DefaultMutableTreeNode {
userObject: "b"
} )
add( new javax.swing.tree.DefaultMutableTreeNode {
userObject: "c"
} )
} )
} )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 2"