mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 15:07:11 -06:00
ScrollPane: if having a column header (e.g. JTable), then increase height of vertical scroll bar so that it also fills the upper right corner
This commit is contained in:
@@ -17,8 +17,10 @@
|
|||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
|
import java.awt.Container;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import java.awt.event.ContainerEvent;
|
import java.awt.event.ContainerEvent;
|
||||||
import java.awt.event.ContainerListener;
|
import java.awt.event.ContainerListener;
|
||||||
import java.awt.event.FocusEvent;
|
import java.awt.event.FocusEvent;
|
||||||
@@ -27,7 +29,9 @@ import java.beans.PropertyChangeEvent;
|
|||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JViewport;
|
import javax.swing.JViewport;
|
||||||
|
import javax.swing.ScrollPaneLayout;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
|
import javax.swing.plaf.UIResource;
|
||||||
import javax.swing.plaf.basic.BasicScrollPaneUI;
|
import javax.swing.plaf.basic.BasicScrollPaneUI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,6 +48,22 @@ public class FlatScrollPaneUI
|
|||||||
return new FlatScrollPaneUI();
|
return new FlatScrollPaneUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void installUI( JComponent c ) {
|
||||||
|
super.installUI( c );
|
||||||
|
|
||||||
|
if( scrollpane.getLayout() instanceof UIResource )
|
||||||
|
scrollpane.setLayout( new FlatScrollPaneLayout() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void uninstallUI( JComponent c ) {
|
||||||
|
if( scrollpane.getLayout() instanceof FlatScrollPaneLayout )
|
||||||
|
scrollpane.setLayout( new ScrollPaneLayout.UIResource() );
|
||||||
|
|
||||||
|
super.uninstallUI( c );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void installListeners( JScrollPane c ) {
|
protected void installListeners( JScrollPane c ) {
|
||||||
super.installListeners( c );
|
super.installListeners( c );
|
||||||
@@ -144,4 +164,27 @@ public class FlatScrollPaneUI
|
|||||||
scrollpane.repaint();
|
scrollpane.repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---- class FlatScrollPaneLayout -----------------------------------------
|
||||||
|
|
||||||
|
private static class FlatScrollPaneLayout
|
||||||
|
extends ScrollPaneLayout
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void layoutContainer( Container parent ) {
|
||||||
|
super.layoutContainer( parent );
|
||||||
|
|
||||||
|
// increase height of vertical scroll bar so that it also fills the upper right corner
|
||||||
|
if( colHead != null && vsb != null && colHead.isVisible() && vsb.isVisible() ) {
|
||||||
|
Rectangle colHeadBounds = colHead.getBounds();
|
||||||
|
Rectangle vsbBounds = vsb.getBounds();
|
||||||
|
|
||||||
|
if( vsbBounds.y > colHeadBounds.y ) {
|
||||||
|
vsbBounds.height += (vsbBounds.y - colHeadBounds.y);
|
||||||
|
vsbBounds.y = colHeadBounds.y;
|
||||||
|
vsb.setBounds( vsbBounds );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user