mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-09 08:15:09 +03:00
TabbedPane: content pane is no longer opaque and use antialiasing for painting separator and content border
This commit is contained in:
@@ -7,6 +7,8 @@ FlatLaf Change Log
|
|||||||
greater than zero.
|
greater than zero.
|
||||||
- TabbedPane: In scroll-tab-layout, the separator line now spans the whole width
|
- TabbedPane: In scroll-tab-layout, the separator line now spans the whole width
|
||||||
and is no longer interrupted by the scroll buttons.
|
and is no longer interrupted by the scroll buttons.
|
||||||
|
- TabbedPane: Content pane is no longer opaque. Use antialiasing for painting
|
||||||
|
separator and content border.
|
||||||
|
|
||||||
|
|
||||||
## 0.17
|
## 0.17
|
||||||
|
|||||||
@@ -24,9 +24,12 @@ import java.awt.Container;
|
|||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.FontMetrics;
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.Shape;
|
import java.awt.Shape;
|
||||||
|
import java.awt.geom.Path2D;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
@@ -112,7 +115,6 @@ public class FlatTabbedPaneUI
|
|||||||
tabAreaInsets = scale( tabAreaInsets );
|
tabAreaInsets = scale( tabAreaInsets );
|
||||||
tabHeight = scale( tabHeight );
|
tabHeight = scale( tabHeight );
|
||||||
tabSelectionHeight = scale( tabSelectionHeight );
|
tabSelectionHeight = scale( tabSelectionHeight );
|
||||||
contentSeparatorHeight = scale( contentSeparatorHeight );
|
|
||||||
|
|
||||||
MigLayoutVisualPadding.install( tabPane, null );
|
MigLayoutVisualPadding.install( tabPane, null );
|
||||||
}
|
}
|
||||||
@@ -196,7 +198,7 @@ public class FlatTabbedPaneUI
|
|||||||
@Override
|
@Override
|
||||||
protected Insets getContentBorderInsets( int tabPlacement ) {
|
protected Insets getContentBorderInsets( int tabPlacement ) {
|
||||||
boolean hasFullBorder = this.hasFullBorder || clientPropertyEquals( tabPane, TABBED_PANE_HAS_FULL_BORDER, true );
|
boolean hasFullBorder = this.hasFullBorder || clientPropertyEquals( tabPane, TABBED_PANE_HAS_FULL_BORDER, true );
|
||||||
int sh = contentSeparatorHeight;
|
int sh = scale( contentSeparatorHeight );
|
||||||
Insets insets = hasFullBorder ? new Insets( sh, sh, sh, sh ) : new Insets( sh, 0, 0, 0 );
|
Insets insets = hasFullBorder ? new Insets( sh, sh, sh, sh ) : new Insets( sh, 0, 0, 0 );
|
||||||
|
|
||||||
Insets contentBorderInsets = new Insets( 0, 0, 0, 0 );
|
Insets contentBorderInsets = new Insets( 0, 0, 0, 0 );
|
||||||
@@ -214,6 +216,13 @@ public class FlatTabbedPaneUI
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update( Graphics g, JComponent c ) {
|
||||||
|
FlatUIUtils.setRenderingHints( (Graphics2D) g );
|
||||||
|
|
||||||
|
super.update( g, c );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintText( Graphics g, int tabPlacement, Font font, FontMetrics metrics,
|
protected void paintText( Graphics g, int tabPlacement, Font font, FontMetrics metrics,
|
||||||
int tabIndex, String title, Rectangle textRect, boolean isSelected )
|
int tabIndex, String title, Rectangle textRect, boolean isSelected )
|
||||||
@@ -270,6 +279,7 @@ public class FlatTabbedPaneUI
|
|||||||
Rectangle clipBounds = isScrollTabLayout() ? g.getClipBounds() : null;
|
Rectangle clipBounds = isScrollTabLayout() ? g.getClipBounds() : null;
|
||||||
if( clipBounds != null ) {
|
if( clipBounds != null ) {
|
||||||
Rectangle newClipBounds = new Rectangle( clipBounds );
|
Rectangle newClipBounds = new Rectangle( clipBounds );
|
||||||
|
int contentSeparatorHeight = scale( this.contentSeparatorHeight );
|
||||||
switch( tabPlacement ) {
|
switch( tabPlacement ) {
|
||||||
case TOP:
|
case TOP:
|
||||||
default:
|
default:
|
||||||
@@ -325,7 +335,6 @@ public class FlatTabbedPaneUI
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Actually does the nearly the same as super.paintContentBorder() but
|
* Actually does the nearly the same as super.paintContentBorder() but
|
||||||
* - content pane is always opaque
|
|
||||||
* - not using UIManager.getColor("TabbedPane.contentAreaColor") to be GUI builder friendly
|
* - not using UIManager.getColor("TabbedPane.contentAreaColor") to be GUI builder friendly
|
||||||
* - not invoking paintContentBorder*Edge() methods
|
* - not invoking paintContentBorder*Edge() methods
|
||||||
* - repaint selection
|
* - repaint selection
|
||||||
@@ -369,9 +378,19 @@ public class FlatTabbedPaneUI
|
|||||||
h -= (y - insets.top);
|
h -= (y - insets.top);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// compute insets for separator or full border
|
||||||
|
boolean hasFullBorder = this.hasFullBorder || clientPropertyEquals( tabPane, TABBED_PANE_HAS_FULL_BORDER, true );
|
||||||
|
int sh = scale( contentSeparatorHeight * 100 ); // multiply by 100 because rotateInsets() does not use floats
|
||||||
|
Insets ci = new Insets( 0, 0, 0, 0 );
|
||||||
|
rotateInsets( hasFullBorder ? new Insets( sh, sh, sh, sh ) : new Insets( sh, 0, 0, 0 ), ci, tabPlacement );
|
||||||
|
|
||||||
// paint content area
|
// paint content area
|
||||||
g.setColor( contentAreaColor );
|
g.setColor( contentAreaColor );
|
||||||
g.fillRect( x, y, w, h );
|
Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD );
|
||||||
|
path.append( new Rectangle2D.Float( x, y, w, h ), false );
|
||||||
|
path.append( new Rectangle2D.Float( x + (ci.left / 100f), y + (ci.top / 100f),
|
||||||
|
w - (ci.left / 100f) - (ci.right / 100f), h - (ci.top / 100f) - (ci.bottom / 100f) ), false );
|
||||||
|
((Graphics2D)g).fill( path );
|
||||||
|
|
||||||
// repaint selection in scroll-tab-layout because it may be painted before
|
// repaint selection in scroll-tab-layout because it may be painted before
|
||||||
// the content border was painted (from BasicTabbedPaneUI$ScrollableTabPanel)
|
// the content border was painted (from BasicTabbedPaneUI$ScrollableTabPanel)
|
||||||
|
|||||||
Reference in New Issue
Block a user