mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 15:07:11 -06:00
TableHeader: do not show resize cursor for last column if resizing last column is not possible because auto resize mode of table is not off (issue #332)
This commit is contained in:
@@ -20,6 +20,8 @@ FlatLaf Change Log
|
|||||||
- OptionPane: Fixed rendering of longer HTML text if it is passed as
|
- OptionPane: Fixed rendering of longer HTML text if it is passed as
|
||||||
`StringBuilder`, `StringBuffer`, or any other object that returns HTML text in
|
`StringBuilder`, `StringBuffer`, or any other object that returns HTML text in
|
||||||
method `toString()`. (similar to issue #12)
|
method `toString()`. (similar to issue #12)
|
||||||
|
- TableHeader: Do not show resize cursor for last column if resizing last column
|
||||||
|
is not possible because auto resize mode of table is not off. (issue #332)
|
||||||
- TextField, FormattedTextField, PasswordField and ComboBox: Fixed alignment of
|
- TextField, FormattedTextField, PasswordField and ComboBox: Fixed alignment of
|
||||||
placeholder text in right-to-left component orientation.
|
placeholder text in right-to-left component orientation.
|
||||||
|
|
||||||
|
|||||||
@@ -18,10 +18,13 @@ package com.formdev.flatlaf.ui;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
|
import java.awt.Cursor;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
@@ -31,6 +34,7 @@ import javax.swing.JTable;
|
|||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
|
import javax.swing.event.MouseInputListener;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.UIResource;
|
import javax.swing.plaf.UIResource;
|
||||||
import javax.swing.plaf.basic.BasicTableHeaderUI;
|
import javax.swing.plaf.basic.BasicTableHeaderUI;
|
||||||
@@ -94,6 +98,11 @@ public class FlatTableHeaderUI
|
|||||||
bottomSeparatorColor = null;
|
bottomSeparatorColor = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected MouseInputListener createMouseInputListener() {
|
||||||
|
return new FlatMouseInputHandler();
|
||||||
|
}
|
||||||
|
|
||||||
// overridden and made public to allow usage in custom renderers
|
// overridden and made public to allow usage in custom renderers
|
||||||
@Override
|
@Override
|
||||||
public int getRolloverColumn() {
|
public int getRolloverColumn() {
|
||||||
@@ -252,4 +261,54 @@ public class FlatTableHeaderUI
|
|||||||
return (origBorder != null) ? origBorder.isBorderOpaque() : false;
|
return (origBorder != null) ? origBorder.isBorderOpaque() : false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---- class FlatMouseInputHandler ----------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 1.6
|
||||||
|
*/
|
||||||
|
protected class FlatMouseInputHandler
|
||||||
|
extends MouseInputHandler
|
||||||
|
{
|
||||||
|
Cursor oldCursor;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseMoved( MouseEvent e ) {
|
||||||
|
// restore old cursor, which is necessary because super.mouseMoved() swaps cursors
|
||||||
|
if( oldCursor != null ) {
|
||||||
|
header.setCursor( oldCursor );
|
||||||
|
oldCursor = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.mouseMoved( e );
|
||||||
|
|
||||||
|
// if resizing last column is not possible, then Swing still shows a resize cursor,
|
||||||
|
// which can be confusing for the user --> change cursor to standard cursor
|
||||||
|
JTable table;
|
||||||
|
int column;
|
||||||
|
if( header.isEnabled() &&
|
||||||
|
(table = header.getTable()) != null &&
|
||||||
|
table.getAutoResizeMode() != JTable.AUTO_RESIZE_OFF &&
|
||||||
|
header.getCursor() == Cursor.getPredefinedCursor( Cursor.E_RESIZE_CURSOR ) &&
|
||||||
|
(column = header.columnAtPoint( e.getPoint() )) >= 0 &&
|
||||||
|
column == header.getColumnModel().getColumnCount() - 1 )
|
||||||
|
{
|
||||||
|
// mouse is in last column
|
||||||
|
Rectangle r = header.getHeaderRect( column );
|
||||||
|
r.grow( -3, 0 );
|
||||||
|
if( !r.contains( e.getX(), e.getY() ) ) {
|
||||||
|
// mouse is in left or right resize area of last column
|
||||||
|
boolean isResizeLastColumn = (e.getX() >= r.x + (r.width / 2));
|
||||||
|
if( !header.getComponentOrientation().isLeftToRight() )
|
||||||
|
isResizeLastColumn = !isResizeLastColumn;
|
||||||
|
|
||||||
|
if( isResizeLastColumn ) {
|
||||||
|
// resize is not possible --> change cursor to standard cursor
|
||||||
|
oldCursor = header.getCursor();
|
||||||
|
header.setCursor( Cursor.getDefaultCursor() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user