mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 15:07:11 -06:00
Table: optionally paint alternating rows below table if table is smaller than scroll pane (issue #504)
This commit is contained in:
@@ -5,6 +5,9 @@ FlatLaf Change Log
|
|||||||
|
|
||||||
#### New features and improvements
|
#### New features and improvements
|
||||||
|
|
||||||
|
- Table: Optionally paint alternating rows below table if table is smaller than
|
||||||
|
scroll pane. Set UI value `Table.paintOutsideAlternateRows` to `true`.
|
||||||
|
Requires that `Table.alternateRowColor` is set to a color. (issue #504)
|
||||||
- ToggleButton: Made the underline placement of tab-style toggle buttons
|
- ToggleButton: Made the underline placement of tab-style toggle buttons
|
||||||
configurable. (PR #530; issue #529)
|
configurable. (PR #530; issue #529)
|
||||||
- Added spanish translation. (PR #525)
|
- Added spanish translation. (PR #525)
|
||||||
@@ -155,7 +158,7 @@ FlatLaf Change Log
|
|||||||
- Possibility to hide window title bar icon (for single window set client
|
- Possibility to hide window title bar icon (for single window set client
|
||||||
property `JRootPane.titleBarShowIcon` to `false`; for all windows set UI
|
property `JRootPane.titleBarShowIcon` to `false`; for all windows set UI
|
||||||
value `TitlePane.showIcon` to `false`).
|
value `TitlePane.showIcon` to `false`).
|
||||||
- OptionPane: Hide window title bar icon by default. Can be be made visibly by
|
- OptionPane: Hide window title bar icon by default. Can be made visibly by
|
||||||
setting UI default `OptionPane.showIcon` to `true`. (issue #416)
|
setting UI default `OptionPane.showIcon` to `true`. (issue #416)
|
||||||
- No longer show the Java "duke/cup" icon if no window icon image is set.
|
- No longer show the Java "duke/cup" icon if no window icon image is set.
|
||||||
(issue #416)
|
(issue #416)
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
* @uiDefault Table.intercellSpacing Dimension
|
* @uiDefault Table.intercellSpacing Dimension
|
||||||
* @uiDefault Table.selectionInactiveBackground Color
|
* @uiDefault Table.selectionInactiveBackground Color
|
||||||
* @uiDefault Table.selectionInactiveForeground Color
|
* @uiDefault Table.selectionInactiveForeground Color
|
||||||
|
* @uiDefault Table.paintOutsideAlternateRows boolean
|
||||||
*
|
*
|
||||||
* <!-- FlatTableCellBorder -->
|
* <!-- FlatTableCellBorder -->
|
||||||
*
|
*
|
||||||
@@ -95,7 +96,7 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
*/
|
*/
|
||||||
public class FlatTableUI
|
public class FlatTableUI
|
||||||
extends BasicTableUI
|
extends BasicTableUI
|
||||||
implements StyleableUI
|
implements StyleableUI, FlatViewportUI.ViewportPainter
|
||||||
{
|
{
|
||||||
protected boolean showHorizontalLines;
|
protected boolean showHorizontalLines;
|
||||||
protected boolean showVerticalLines;
|
protected boolean showVerticalLines;
|
||||||
@@ -421,4 +422,38 @@ public class FlatTableUI
|
|||||||
? (viewport != rowHeader)
|
? (viewport != rowHeader)
|
||||||
: (viewport == rowHeader || rowHeader == null);
|
: (viewport == rowHeader || rowHeader == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 2.3 */
|
||||||
|
@Override
|
||||||
|
public void paintViewport( Graphics g, JComponent c, JViewport viewport ) {
|
||||||
|
int viewportWidth = viewport.getWidth();
|
||||||
|
int viewportHeight = viewport.getHeight();
|
||||||
|
|
||||||
|
// fill viewport background in same color as table background
|
||||||
|
if( viewport.isOpaque() ) {
|
||||||
|
g.setColor( table.getBackground() );
|
||||||
|
g.fillRect( 0, 0, viewportWidth, viewportHeight );
|
||||||
|
}
|
||||||
|
|
||||||
|
// paint alternating empty rows
|
||||||
|
boolean paintOutside = UIManager.getBoolean( "Table.paintOutsideAlternateRows" );
|
||||||
|
Color alternateColor;
|
||||||
|
if( paintOutside && (alternateColor = UIManager.getColor( "Table.alternateRowColor" )) != null ) {
|
||||||
|
g.setColor( alternateColor );
|
||||||
|
|
||||||
|
int rowCount = table.getRowCount();
|
||||||
|
|
||||||
|
// paint alternating empty rows below the table
|
||||||
|
int tableHeight = table.getHeight();
|
||||||
|
if( tableHeight < viewportHeight ) {
|
||||||
|
int tableWidth = table.getWidth();
|
||||||
|
int rowHeight = table.getRowHeight();
|
||||||
|
|
||||||
|
for( int y = tableHeight, row = rowCount; y < viewportHeight; y += rowHeight, row++ ) {
|
||||||
|
if( row % 2 != 0 )
|
||||||
|
g.fillRect( 0, y, tableWidth, rowHeight );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ package com.formdev.flatlaf.ui;
|
|||||||
|
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JTable;
|
|
||||||
import javax.swing.JViewport;
|
import javax.swing.JViewport;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicViewportUI;
|
import javax.swing.plaf.basic.BasicViewportUI;
|
||||||
@@ -43,15 +43,28 @@ public class FlatViewportUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update( Graphics g, JComponent c ) {
|
public void paint( Graphics g, JComponent c ) {
|
||||||
Component view = ((JViewport)c).getView();
|
super.paint( g, c );
|
||||||
if( c.isOpaque() && view instanceof JTable ) {
|
|
||||||
// paint viewport background in same color as table background
|
|
||||||
g.setColor( view.getBackground() );
|
|
||||||
g.fillRect( 0, 0, c.getWidth(), c.getHeight() );
|
|
||||||
|
|
||||||
paint( g, c );
|
Component view = ((JViewport)c).getView();
|
||||||
} else
|
if( view instanceof JComponent ) {
|
||||||
super.update( g, c );
|
try {
|
||||||
|
Method m = view.getClass().getMethod( "getUI" );
|
||||||
|
Object ui = m.invoke( view );
|
||||||
|
if( ui instanceof ViewportPainter )
|
||||||
|
((ViewportPainter)ui).paintViewport( g, (JComponent) view, (JViewport) c );
|
||||||
|
} catch( Exception ex ) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---- interface ViewportPainter ------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 2.3
|
||||||
|
*/
|
||||||
|
public interface ViewportPainter {
|
||||||
|
void paintViewport( Graphics g, JComponent c, JViewport viewport );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -336,6 +336,16 @@ public class FlatComponents2Test
|
|||||||
table.setSurrendersFocusOnKeystroke( focusCellEditorCheckBox.isSelected() );
|
table.setSurrendersFocusOnKeystroke( focusCellEditorCheckBox.isSelected() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void alternatingRowsChanged() {
|
||||||
|
UIManager.put( "Table.alternateRowColor", alternatingRowsCheckBox.isSelected() ? Color.orange : null );
|
||||||
|
table1ScrollPane.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void paintOutsideAlternateRowsChanged() {
|
||||||
|
UIManager.put( "Table.paintOutsideAlternateRows", paintOutsideAlternateRowsCheckBox.isSelected() ? true : null );
|
||||||
|
table1ScrollPane.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
private void treeRendererChanged() {
|
private void treeRendererChanged() {
|
||||||
Object sel = treeRendererComboBox.getSelectedItem();
|
Object sel = treeRendererComboBox.getSelectedItem();
|
||||||
if( !(sel instanceof String) )
|
if( !(sel instanceof String) )
|
||||||
@@ -493,8 +503,10 @@ public class FlatComponents2Test
|
|||||||
focusCellEditorCheckBox = new JCheckBox();
|
focusCellEditorCheckBox = new JCheckBox();
|
||||||
showVerticalLinesCheckBox = new JCheckBox();
|
showVerticalLinesCheckBox = new JCheckBox();
|
||||||
columnSelectionCheckBox = new JCheckBox();
|
columnSelectionCheckBox = new JCheckBox();
|
||||||
|
alternatingRowsCheckBox = new JCheckBox();
|
||||||
intercellSpacingCheckBox = new JCheckBox();
|
intercellSpacingCheckBox = new JCheckBox();
|
||||||
rowHeaderCheckBox = new JCheckBox();
|
rowHeaderCheckBox = new JCheckBox();
|
||||||
|
paintOutsideAlternateRowsCheckBox = new JCheckBox();
|
||||||
redGridColorCheckBox = new JCheckBox();
|
redGridColorCheckBox = new JCheckBox();
|
||||||
tableHeaderButtonCheckBox = new JCheckBox();
|
tableHeaderButtonCheckBox = new JCheckBox();
|
||||||
|
|
||||||
@@ -875,6 +887,11 @@ public class FlatComponents2Test
|
|||||||
columnSelectionCheckBox.addActionListener(e -> columnSelectionChanged());
|
columnSelectionCheckBox.addActionListener(e -> columnSelectionChanged());
|
||||||
tableOptionsPanel.add(columnSelectionCheckBox, "cell 1 2");
|
tableOptionsPanel.add(columnSelectionCheckBox, "cell 1 2");
|
||||||
|
|
||||||
|
//---- alternatingRowsCheckBox ----
|
||||||
|
alternatingRowsCheckBox.setText("alternating rows");
|
||||||
|
alternatingRowsCheckBox.addActionListener(e -> alternatingRowsChanged());
|
||||||
|
tableOptionsPanel.add(alternatingRowsCheckBox, "cell 2 2");
|
||||||
|
|
||||||
//---- intercellSpacingCheckBox ----
|
//---- intercellSpacingCheckBox ----
|
||||||
intercellSpacingCheckBox.setText("intercell spacing");
|
intercellSpacingCheckBox.setText("intercell spacing");
|
||||||
intercellSpacingCheckBox.addActionListener(e -> intercellSpacingChanged());
|
intercellSpacingCheckBox.addActionListener(e -> intercellSpacingChanged());
|
||||||
@@ -885,6 +902,11 @@ public class FlatComponents2Test
|
|||||||
rowHeaderCheckBox.addActionListener(e -> rowHeaderChanged());
|
rowHeaderCheckBox.addActionListener(e -> rowHeaderChanged());
|
||||||
tableOptionsPanel.add(rowHeaderCheckBox, "cell 1 3");
|
tableOptionsPanel.add(rowHeaderCheckBox, "cell 1 3");
|
||||||
|
|
||||||
|
//---- paintOutsideAlternateRowsCheckBox ----
|
||||||
|
paintOutsideAlternateRowsCheckBox.setText("outside alternating rows");
|
||||||
|
paintOutsideAlternateRowsCheckBox.addActionListener(e -> paintOutsideAlternateRowsChanged());
|
||||||
|
tableOptionsPanel.add(paintOutsideAlternateRowsCheckBox, "cell 2 3");
|
||||||
|
|
||||||
//---- redGridColorCheckBox ----
|
//---- redGridColorCheckBox ----
|
||||||
redGridColorCheckBox.setText("red grid color");
|
redGridColorCheckBox.setText("red grid color");
|
||||||
redGridColorCheckBox.addActionListener(e -> redGridColorChanged());
|
redGridColorCheckBox.addActionListener(e -> redGridColorChanged());
|
||||||
@@ -927,8 +949,10 @@ public class FlatComponents2Test
|
|||||||
private JCheckBox focusCellEditorCheckBox;
|
private JCheckBox focusCellEditorCheckBox;
|
||||||
private JCheckBox showVerticalLinesCheckBox;
|
private JCheckBox showVerticalLinesCheckBox;
|
||||||
private JCheckBox columnSelectionCheckBox;
|
private JCheckBox columnSelectionCheckBox;
|
||||||
|
private JCheckBox alternatingRowsCheckBox;
|
||||||
private JCheckBox intercellSpacingCheckBox;
|
private JCheckBox intercellSpacingCheckBox;
|
||||||
private JCheckBox rowHeaderCheckBox;
|
private JCheckBox rowHeaderCheckBox;
|
||||||
|
private JCheckBox paintOutsideAlternateRowsCheckBox;
|
||||||
private JCheckBox redGridColorCheckBox;
|
private JCheckBox redGridColorCheckBox;
|
||||||
private JCheckBox tableHeaderButtonCheckBox;
|
private JCheckBox tableHeaderButtonCheckBox;
|
||||||
// JFormDesigner - End of variables declaration //GEN-END:variables
|
// JFormDesigner - End of variables declaration //GEN-END:variables
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
JFDML JFormDesigner: "7.0.5.0.382" Java: "16" encoding: "UTF-8"
|
JFDML JFormDesigner: "7.0.5.0.404" Java: "17.0.2" encoding: "UTF-8"
|
||||||
|
|
||||||
new FormModel {
|
new FormModel {
|
||||||
contentType: "form/swing"
|
contentType: "form/swing"
|
||||||
@@ -485,6 +485,16 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 1 2"
|
"value": "cell 1 2"
|
||||||
} )
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||||
|
name: "alternatingRowsCheckBox"
|
||||||
|
"text": "alternating rows"
|
||||||
|
auxiliary() {
|
||||||
|
"JavaCodeGenerator.variableLocal": false
|
||||||
|
}
|
||||||
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "alternatingRowsChanged", false ) )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 2 2"
|
||||||
|
} )
|
||||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||||
name: "intercellSpacingCheckBox"
|
name: "intercellSpacingCheckBox"
|
||||||
"text": "intercell spacing"
|
"text": "intercell spacing"
|
||||||
@@ -505,6 +515,16 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 1 3"
|
"value": "cell 1 3"
|
||||||
} )
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||||
|
name: "paintOutsideAlternateRowsCheckBox"
|
||||||
|
"text": "outside alternating rows"
|
||||||
|
auxiliary() {
|
||||||
|
"JavaCodeGenerator.variableLocal": false
|
||||||
|
}
|
||||||
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "paintOutsideAlternateRowsChanged", false ) )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 2 3"
|
||||||
|
} )
|
||||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||||
name: "redGridColorCheckBox"
|
name: "redGridColorCheckBox"
|
||||||
"text": "red grid color"
|
"text": "red grid color"
|
||||||
|
|||||||
Reference in New Issue
Block a user