mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 22:47:13 -06:00
TabbedPane: fixed actions scrollTabsForwardAction and scrollTabsBackwardAction when used from outside (e.g. in NetBeans)
This commit is contained in:
@@ -18,7 +18,10 @@ package com.formdev.flatlaf.testing;
|
||||
|
||||
import static com.formdev.flatlaf.FlatClientProperties.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import com.formdev.flatlaf.FlatLaf;
|
||||
@@ -418,6 +421,32 @@ public class FlatContainerTest
|
||||
tabbedPane.setMaximumTabWidth( maximumTabWidth );
|
||||
}
|
||||
|
||||
private void customWheelScrollingChanged() {
|
||||
if( custoMouseWheelScroller != null ) {
|
||||
for( FlatTabbedPane tabbedPane : allTabbedPanes )
|
||||
tabbedPane.removeMouseWheelListener( custoMouseWheelScroller );
|
||||
custoMouseWheelScroller = null;
|
||||
}
|
||||
|
||||
if( customWheelScrollingCheckBox.isSelected() ) {
|
||||
custoMouseWheelScroller = new MouseWheelListener() {
|
||||
@Override
|
||||
public void mouseWheelMoved( MouseWheelEvent e ) {
|
||||
if( e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL ) {
|
||||
JTabbedPane tabbedPane = (JTabbedPane) e.getComponent();
|
||||
ActionMap actionMap = tabbedPane.getActionMap();
|
||||
Action scrollAction = actionMap.get( (e.getWheelRotation() < 0)
|
||||
? "scrollTabsBackwardAction" : "scrollTabsForwardAction" );
|
||||
if( scrollAction != null && scrollAction.isEnabled() )
|
||||
scrollAction.actionPerformed( new ActionEvent( tabbedPane, 0, "" ) );
|
||||
}
|
||||
}
|
||||
};
|
||||
for( FlatTabbedPane tabbedPane : allTabbedPanes )
|
||||
tabbedPane.addMouseWheelListener( custoMouseWheelScroller );
|
||||
}
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
||||
JPanel panel9 = new JPanel();
|
||||
@@ -475,6 +504,7 @@ public class FlatContainerTest
|
||||
showTabSeparatorsCheckBox = new JCheckBox();
|
||||
secondTabWiderCheckBox = new JCheckBox();
|
||||
hideTabAreaWithOneTabCheckBox = new JCheckBox();
|
||||
customWheelScrollingCheckBox = new JCheckBox();
|
||||
CellConstraints cc = new CellConstraints();
|
||||
|
||||
//======== this ========
|
||||
@@ -773,6 +803,11 @@ public class FlatContainerTest
|
||||
hideTabAreaWithOneTabCheckBox.setText("Hide tab area with one tab");
|
||||
hideTabAreaWithOneTabCheckBox.addActionListener(e -> hideTabAreaWithOneTabChanged());
|
||||
tabbedPaneControlPanel.add(hideTabAreaWithOneTabCheckBox, "cell 1 10");
|
||||
|
||||
//---- customWheelScrollingCheckBox ----
|
||||
customWheelScrollingCheckBox.setText("Custom wheel scrolling");
|
||||
customWheelScrollingCheckBox.addActionListener(e -> customWheelScrollingChanged());
|
||||
tabbedPaneControlPanel.add(customWheelScrollingCheckBox, "cell 2 10");
|
||||
}
|
||||
panel9.add(tabbedPaneControlPanel, cc.xywh(1, 11, 3, 1));
|
||||
}
|
||||
@@ -818,9 +853,11 @@ public class FlatContainerTest
|
||||
private JCheckBox showTabSeparatorsCheckBox;
|
||||
private JCheckBox secondTabWiderCheckBox;
|
||||
private JCheckBox hideTabAreaWithOneTabCheckBox;
|
||||
private JCheckBox customWheelScrollingCheckBox;
|
||||
// JFormDesigner - End of variables declaration //GEN-END:variables
|
||||
|
||||
private FlatTabbedPane[] allTabbedPanes;
|
||||
private MouseWheelListener custoMouseWheelScroller;
|
||||
|
||||
//---- enum TabPlacement --------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
JFDML JFormDesigner: "7.0.2.0.298" Java: "15" encoding: "UTF-8"
|
||||
JFDML JFormDesigner: "7.0.3.1.342" Java: "16" encoding: "UTF-8"
|
||||
|
||||
new FormModel {
|
||||
contentType: "form/swing"
|
||||
@@ -502,6 +502,16 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 10"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||
name: "customWheelScrollingCheckBox"
|
||||
"text": "Custom wheel scrolling"
|
||||
auxiliary() {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "customWheelScrollingChanged", false ) )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 10"
|
||||
} )
|
||||
}, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) {
|
||||
"gridY": 11
|
||||
"gridWidth": 3
|
||||
|
||||
Reference in New Issue
Block a user