mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 23:37:13 -06:00
ScrollBar implemented
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2019 FormDev Software GmbH
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.formdev.flatlaf.ui;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.basic.BasicScrollBarUI;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
|
||||
/**
|
||||
* Provides the Flat LaF UI delegate for {@link javax.swing.JScrollBar}.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatScrollBarUI
|
||||
extends BasicScrollBarUI
|
||||
{
|
||||
public static ComponentUI createUI( JComponent c ) {
|
||||
return new FlatScrollBarUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize( JComponent c ) {
|
||||
return UIScale.scale( super.getPreferredSize( c ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JButton createDecreaseButton( int orientation ) {
|
||||
return createInvisibleButton();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JButton createIncreaseButton( int orientation ) {
|
||||
return createInvisibleButton();
|
||||
}
|
||||
|
||||
private JButton createInvisibleButton() {
|
||||
JButton button = new JButton();
|
||||
button.setMinimumSize( new Dimension() );
|
||||
button.setMaximumSize( new Dimension() );
|
||||
button.setPreferredSize( new Dimension() );
|
||||
button.setFocusable( false );
|
||||
button.setRequestFocusEnabled( false );
|
||||
return button;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintDecreaseHighlight( Graphics g ) {
|
||||
// do not paint
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintIncreaseHighlight( Graphics g ) {
|
||||
// do not paint
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintThumb( Graphics g, JComponent c, Rectangle thumbBounds ) {
|
||||
if( thumbBounds.isEmpty() || !scrollbar.isEnabled() )
|
||||
return;
|
||||
|
||||
g.setColor( thumbColor );
|
||||
g.fillRect( thumbBounds.x, thumbBounds.y, thumbBounds.width, thumbBounds.height );
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.formdev.flatlaf.util;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
@@ -24,6 +25,8 @@ import java.beans.PropertyChangeListener;
|
||||
import java.lang.reflect.Method;
|
||||
import javax.swing.LookAndFeel;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.DimensionUIResource;
|
||||
import javax.swing.plaf.UIResource;
|
||||
|
||||
/**
|
||||
* Two scaling modes are supported for HiDPI displays:
|
||||
@@ -184,4 +187,12 @@ public class UIScale
|
||||
if( scaleFactor != 1f )
|
||||
g.scale( scaleFactor, scaleFactor );
|
||||
}
|
||||
|
||||
public static Dimension scale( Dimension dimension ) {
|
||||
return (dimension == null || scaleFactor == 1f)
|
||||
? dimension
|
||||
: (dimension instanceof UIResource
|
||||
? new DimensionUIResource( scale( dimension.width ), scale( dimension.height ) )
|
||||
: new Dimension ( scale( dimension.width ), scale( dimension.height ) ));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,3 +89,9 @@ Component.focusColor=3d6185
|
||||
#---- Label ----
|
||||
|
||||
Label.disabledForeground=@disabledText
|
||||
|
||||
|
||||
#---- ScrollBar ----
|
||||
|
||||
ScrollBar.track=3F4244
|
||||
ScrollBar.thumb=47A6A6A6
|
||||
|
||||
@@ -23,6 +23,7 @@ FormattedTextFieldUI=com.formdev.flatlaf.ui.FlatFormattedTextFieldUI
|
||||
LabelUI=com.formdev.flatlaf.ui.FlatLabelUI
|
||||
PasswordFieldUI=com.formdev.flatlaf.ui.FlatPasswordFieldUI
|
||||
RadioButtonUI=com.formdev.flatlaf.ui.FlatRadioButtonUI
|
||||
ScrollBarUI=com.formdev.flatlaf.ui.FlatScrollBarUI
|
||||
ScrollPaneUI=com.formdev.flatlaf.ui.FlatScrollPaneUI
|
||||
TextAreaUI=com.formdev.flatlaf.ui.FlatTextAreaUI
|
||||
TextFieldUI=com.formdev.flatlaf.ui.FlatTextFieldUI
|
||||
@@ -79,6 +80,11 @@ RadioButton.border=com.formdev.flatlaf.ui.FlatMarginBorder
|
||||
RadioButton.icon=com.formdev.flatlaf.ui.FlatRadioButtonIcon
|
||||
|
||||
|
||||
#---- ScrollBar ----
|
||||
|
||||
ScrollBar.width=10
|
||||
|
||||
|
||||
#---- ScrollPane ----
|
||||
|
||||
ScrollPane.border=com.formdev.flatlaf.ui.FlatBorder
|
||||
|
||||
@@ -89,3 +89,9 @@ Component.focusColor=97c3f3
|
||||
#---- Label ----
|
||||
|
||||
Label.disabledForeground=@disabledText
|
||||
|
||||
|
||||
#---- ScrollBar ----
|
||||
|
||||
ScrollBar.track=F5F5F5
|
||||
ScrollBar.thumb=33737373
|
||||
|
||||
Reference in New Issue
Block a user