Skip to content

Commit

Permalink
updated CHANGELOG.md for PR #595 and added tab context menu test
Browse files Browse the repository at this point in the history
  • Loading branch information
DevCharly committed Sep 30, 2022
1 parent 0699454 commit 6e7c2a6
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@ FlatLaf Change Log

- ComboBox and Spinner: Fixed missing arrow buttons if preferred height is zero.
Minimum width of arrow buttons is 3/4 of default width.
- TabbedPane: Switch and close tabs on left mouse click only. (PR #595)


## 2.5
Expand Down
Expand Up @@ -19,7 +19,9 @@
import static com.formdev.flatlaf.FlatClientProperties.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import javax.swing.*;
Expand Down Expand Up @@ -430,14 +432,14 @@ private void maximumTabWidthChanged() {
}

private void customWheelScrollingChanged() {
if( custoMouseWheelScroller != null ) {
if( customMouseWheelScroller != null ) {
for( FlatTabbedPane tabbedPane : allTabbedPanes )
tabbedPane.removeMouseWheelListener( custoMouseWheelScroller );
custoMouseWheelScroller = null;
tabbedPane.removeMouseWheelListener( customMouseWheelScroller );
customMouseWheelScroller = null;
}

if( customWheelScrollingCheckBox.isSelected() ) {
custoMouseWheelScroller = new MouseWheelListener() {
customMouseWheelScroller = new MouseWheelListener() {
@Override
public void mouseWheelMoved( MouseWheelEvent e ) {
if( e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL ) {
Expand All @@ -451,7 +453,45 @@ public void mouseWheelMoved( MouseWheelEvent e ) {
}
};
for( FlatTabbedPane tabbedPane : allTabbedPanes )
tabbedPane.addMouseWheelListener( custoMouseWheelScroller );
tabbedPane.addMouseWheelListener( customMouseWheelScroller );
}
}

private void contextMenuChanged() {
if( contextMenuListener != null ) {
for( FlatTabbedPane tabbedPane : allTabbedPanes )
tabbedPane.removeMouseListener( contextMenuListener );
contextMenuListener = null;
}

if( contextMenuCheckBox.isSelected() ) {
contextMenuListener = new MouseAdapter() {
@Override
public void mousePressed( MouseEvent e ) {
popupMenu( e );
}
@Override
public void mouseReleased( MouseEvent e ) {
popupMenu( e );
}
private void popupMenu( MouseEvent e ) {
if( !e.isPopupTrigger() )
return;

JTabbedPane tabbedPane = (JTabbedPane) e.getComponent();
int tabIndex = tabbedPane.indexAtLocation( e.getX(), e.getY() );
if( tabIndex < 0 )
return;

JPopupMenu popupMenu = new JPopupMenu();
popupMenu.add( "item 1" );
popupMenu.add( "item 2" );
popupMenu.add( "item 3" );
popupMenu.show( tabbedPane, e.getX(), e.getY() );
}
};
for( FlatTabbedPane tabbedPane : allTabbedPanes )
tabbedPane.addMouseListener( contextMenuListener );
}
}

Expand Down Expand Up @@ -515,6 +555,7 @@ private void initComponents() {
secondTabWiderCheckBox = new JCheckBox();
hideTabAreaWithOneTabCheckBox = new JCheckBox();
customWheelScrollingCheckBox = new JCheckBox();
contextMenuCheckBox = new JCheckBox();
CellConstraints cc = new CellConstraints();

//======== this ========
Expand Down Expand Up @@ -546,11 +587,11 @@ private void initComponents() {
splitPane1.setOneTouchExpandable(true);

//---- panel15 ----
panel15.setBackground(new Color(217, 163, 67));
panel15.setBackground(new Color(0xd9a343));
splitPane1.setLeftComponent(panel15);

//---- panel21 ----
panel21.setBackground(new Color(98, 181, 67));
panel21.setBackground(new Color(0x62b543));
splitPane1.setRightComponent(panel21);
}
splitPane3.setLeftComponent(splitPane1);
Expand All @@ -563,7 +604,7 @@ private void initComponents() {

//======== panel12 ========
{
panel12.setBackground(new Color(242, 101, 34));
panel12.setBackground(new Color(0xf26522));
panel12.setLayout(new BorderLayout());

//---- label3 ----
Expand All @@ -576,7 +617,7 @@ private void initComponents() {

//======== panel13 ========
{
panel13.setBackground(new Color(64, 182, 224));
panel13.setBackground(new Color(0x40b6e0));
panel13.setLayout(new BorderLayout());

//---- label4 ----
Expand Down Expand Up @@ -636,6 +677,7 @@ private void initComponents() {
"[]para" +
"[]" +
"[]" +
"[]" +
"[]"));

//---- tabScrollCheckBox ----
Expand Down Expand Up @@ -828,6 +870,11 @@ private void initComponents() {
customWheelScrollingCheckBox.setText("Custom wheel scrolling");
customWheelScrollingCheckBox.addActionListener(e -> customWheelScrollingChanged());
tabbedPaneControlPanel.add(customWheelScrollingCheckBox, "cell 2 11");

//---- contextMenuCheckBox ----
contextMenuCheckBox.setText("Context menu on tabs");
contextMenuCheckBox.addActionListener(e -> contextMenuChanged());
tabbedPaneControlPanel.add(contextMenuCheckBox, "cell 2 12");
}
panel9.add(tabbedPaneControlPanel, cc.xywh(1, 11, 3, 1));
}
Expand Down Expand Up @@ -875,10 +922,12 @@ private void initComponents() {
private JCheckBox secondTabWiderCheckBox;
private JCheckBox hideTabAreaWithOneTabCheckBox;
private JCheckBox customWheelScrollingCheckBox;
private JCheckBox contextMenuCheckBox;
// JFormDesigner - End of variables declaration //GEN-END:variables

private FlatTabbedPane[] allTabbedPanes;
private MouseWheelListener custoMouseWheelScroller;
private MouseWheelListener customMouseWheelScroller;
private MouseListener contextMenuListener;

//---- enum TabPlacement --------------------------------------------------

Expand Down
@@ -1,4 +1,4 @@
JFDML JFormDesigner: "7.0.3.1.342" Java: "16" encoding: "UTF-8"
JFDML JFormDesigner: "8.0.0.0.194" Java: "17.0.2" encoding: "UTF-8"

new FormModel {
contentType: "form/swing"
Expand Down Expand Up @@ -132,7 +132,7 @@ new FormModel {
add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestFrame$NoRightToLeftPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "insets 0,hidemode 3"
"$columnConstraints": "[][fill][]"
"$rowConstraints": "[center][][][][][][]para[][]para[][][]"
"$rowConstraints": "[center][][][][][][]para[][]para[][][][]"
} ) {
name: "tabbedPaneControlPanel"
"opaque": false
Expand Down Expand Up @@ -529,6 +529,16 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 11"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "contextMenuCheckBox"
"text": "Context menu on tabs"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "contextMenuChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 12"
} )
}, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) {
"gridY": 11
"gridWidth": 3
Expand Down

0 comments on commit 6e7c2a6

Please sign in to comment.