mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-10 22:17: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;
|
package com.formdev.flatlaf.util;
|
||||||
|
|
||||||
|
import java.awt.Dimension;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.GraphicsEnvironment;
|
import java.awt.GraphicsEnvironment;
|
||||||
@@ -24,6 +25,8 @@ import java.beans.PropertyChangeListener;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import javax.swing.LookAndFeel;
|
import javax.swing.LookAndFeel;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
import javax.swing.plaf.DimensionUIResource;
|
||||||
|
import javax.swing.plaf.UIResource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Two scaling modes are supported for HiDPI displays:
|
* Two scaling modes are supported for HiDPI displays:
|
||||||
@@ -184,4 +187,12 @@ public class UIScale
|
|||||||
if( scaleFactor != 1f )
|
if( scaleFactor != 1f )
|
||||||
g.scale( scaleFactor, scaleFactor );
|
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 ----
|
||||||
|
|
||||||
Label.disabledForeground=@disabledText
|
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
|
LabelUI=com.formdev.flatlaf.ui.FlatLabelUI
|
||||||
PasswordFieldUI=com.formdev.flatlaf.ui.FlatPasswordFieldUI
|
PasswordFieldUI=com.formdev.flatlaf.ui.FlatPasswordFieldUI
|
||||||
RadioButtonUI=com.formdev.flatlaf.ui.FlatRadioButtonUI
|
RadioButtonUI=com.formdev.flatlaf.ui.FlatRadioButtonUI
|
||||||
|
ScrollBarUI=com.formdev.flatlaf.ui.FlatScrollBarUI
|
||||||
ScrollPaneUI=com.formdev.flatlaf.ui.FlatScrollPaneUI
|
ScrollPaneUI=com.formdev.flatlaf.ui.FlatScrollPaneUI
|
||||||
TextAreaUI=com.formdev.flatlaf.ui.FlatTextAreaUI
|
TextAreaUI=com.formdev.flatlaf.ui.FlatTextAreaUI
|
||||||
TextFieldUI=com.formdev.flatlaf.ui.FlatTextFieldUI
|
TextFieldUI=com.formdev.flatlaf.ui.FlatTextFieldUI
|
||||||
@@ -79,6 +80,11 @@ RadioButton.border=com.formdev.flatlaf.ui.FlatMarginBorder
|
|||||||
RadioButton.icon=com.formdev.flatlaf.ui.FlatRadioButtonIcon
|
RadioButton.icon=com.formdev.flatlaf.ui.FlatRadioButtonIcon
|
||||||
|
|
||||||
|
|
||||||
|
#---- ScrollBar ----
|
||||||
|
|
||||||
|
ScrollBar.width=10
|
||||||
|
|
||||||
|
|
||||||
#---- ScrollPane ----
|
#---- ScrollPane ----
|
||||||
|
|
||||||
ScrollPane.border=com.formdev.flatlaf.ui.FlatBorder
|
ScrollPane.border=com.formdev.flatlaf.ui.FlatBorder
|
||||||
|
|||||||
@@ -89,3 +89,9 @@ Component.focusColor=97c3f3
|
|||||||
#---- Label ----
|
#---- Label ----
|
||||||
|
|
||||||
Label.disabledForeground=@disabledText
|
Label.disabledForeground=@disabledText
|
||||||
|
|
||||||
|
|
||||||
|
#---- ScrollBar ----
|
||||||
|
|
||||||
|
ScrollBar.track=F5F5F5
|
||||||
|
ScrollBar.thumb=33737373
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf;
|
package com.formdev.flatlaf;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import net.miginfocom.swing.*;
|
import net.miginfocom.swing.*;
|
||||||
|
|
||||||
@@ -111,6 +112,15 @@ public class FlatComponentsTest
|
|||||||
JScrollPane scrollPane12 = new JScrollPane();
|
JScrollPane scrollPane12 = new JScrollPane();
|
||||||
JTextPane textPane4 = new JTextPane();
|
JTextPane textPane4 = new JTextPane();
|
||||||
JTextPane textPane5 = new JTextPane();
|
JTextPane textPane5 = new JTextPane();
|
||||||
|
JLabel scrollPaneLabel = new JLabel();
|
||||||
|
JScrollPane scrollPane13 = new JScrollPane();
|
||||||
|
JPanel panel1 = new JPanel();
|
||||||
|
JScrollBar scrollBar2 = new JScrollBar();
|
||||||
|
JScrollBar scrollBar3 = new JScrollBar();
|
||||||
|
JScrollPane scrollPane14 = new JScrollPane();
|
||||||
|
JLabel scrollBarLabel = new JLabel();
|
||||||
|
JScrollBar scrollBar1 = new JScrollBar();
|
||||||
|
JScrollBar scrollBar4 = new JScrollBar();
|
||||||
|
|
||||||
//======== this ========
|
//======== this ========
|
||||||
setLayout(new MigLayout(
|
setLayout(new MigLayout(
|
||||||
@@ -132,6 +142,9 @@ public class FlatComponentsTest
|
|||||||
"[]" +
|
"[]" +
|
||||||
"[]" +
|
"[]" +
|
||||||
"[]" +
|
"[]" +
|
||||||
|
"[]" +
|
||||||
|
"[]" +
|
||||||
|
"[]" +
|
||||||
"[]"));
|
"[]"));
|
||||||
|
|
||||||
//---- labelLabel ----
|
//---- labelLabel ----
|
||||||
@@ -476,6 +489,43 @@ public class FlatComponentsTest
|
|||||||
//---- textPane5 ----
|
//---- textPane5 ----
|
||||||
textPane5.setText("no scroll pane");
|
textPane5.setText("no scroll pane");
|
||||||
add(textPane5, "cell 5 9,growx");
|
add(textPane5, "cell 5 9,growx");
|
||||||
|
|
||||||
|
//---- scrollPaneLabel ----
|
||||||
|
scrollPaneLabel.setText("JScrollPane:");
|
||||||
|
add(scrollPaneLabel, "cell 0 10");
|
||||||
|
|
||||||
|
//======== scrollPane13 ========
|
||||||
|
{
|
||||||
|
scrollPane13.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
|
||||||
|
scrollPane13.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
||||||
|
|
||||||
|
//======== panel1 ========
|
||||||
|
{
|
||||||
|
panel1.setPreferredSize(new Dimension(200, 200));
|
||||||
|
panel1.setLayout(new BorderLayout());
|
||||||
|
}
|
||||||
|
scrollPane13.setViewportView(panel1);
|
||||||
|
}
|
||||||
|
add(scrollPane13, "cell 1 10,grow,width 70,height 70");
|
||||||
|
add(scrollBar2, "cell 2 10,growy");
|
||||||
|
|
||||||
|
//---- scrollBar3 ----
|
||||||
|
scrollBar3.setEnabled(false);
|
||||||
|
add(scrollBar3, "cell 2 10,growy");
|
||||||
|
add(scrollPane14, "cell 3 10,grow");
|
||||||
|
|
||||||
|
//---- scrollBarLabel ----
|
||||||
|
scrollBarLabel.setText("JScrollBar:");
|
||||||
|
add(scrollBarLabel, "cell 0 11");
|
||||||
|
|
||||||
|
//---- scrollBar1 ----
|
||||||
|
scrollBar1.setOrientation(Adjustable.HORIZONTAL);
|
||||||
|
add(scrollBar1, "cell 1 11,growx");
|
||||||
|
|
||||||
|
//---- scrollBar4 ----
|
||||||
|
scrollBar4.setOrientation(Adjustable.HORIZONTAL);
|
||||||
|
scrollBar4.setEnabled(false);
|
||||||
|
add(scrollBar4, "cell 1 12,growx");
|
||||||
// JFormDesigner - End of component initialization //GEN-END:initComponents
|
// JFormDesigner - End of component initialization //GEN-END:initComponents
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ new FormModel {
|
|||||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
||||||
"$layoutConstraints": "insets 0,hidemode 3,gap 5 5"
|
"$layoutConstraints": "insets 0,hidemode 3,gap 5 5"
|
||||||
"$columnConstraints": "[][][][][][]"
|
"$columnConstraints": "[][][][][][]"
|
||||||
"$rowConstraints": "[][][][][][][][][][]"
|
"$rowConstraints": "[][][][][][][][][][][][][]"
|
||||||
} ) {
|
} ) {
|
||||||
name: "this"
|
name: "this"
|
||||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
@@ -435,9 +435,61 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 5 9,growx"
|
"value": "cell 5 9,growx"
|
||||||
} )
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
|
name: "scrollPaneLabel"
|
||||||
|
"text": "JScrollPane:"
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 0 10"
|
||||||
|
} )
|
||||||
|
add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) {
|
||||||
|
name: "scrollPane13"
|
||||||
|
"horizontalScrollBarPolicy": 32
|
||||||
|
"verticalScrollBarPolicy": 22
|
||||||
|
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.BorderLayout ) ) {
|
||||||
|
name: "panel1"
|
||||||
|
"preferredSize": new java.awt.Dimension( 200, 200 )
|
||||||
|
} )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 10,grow,width 70,height 70"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JScrollBar" ) {
|
||||||
|
name: "scrollBar2"
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 2 10,growy"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JScrollBar" ) {
|
||||||
|
name: "scrollBar3"
|
||||||
|
"enabled": false
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 2 10,growy"
|
||||||
|
} )
|
||||||
|
add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) {
|
||||||
|
name: "scrollPane14"
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 3 10,grow"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
|
name: "scrollBarLabel"
|
||||||
|
"text": "JScrollBar:"
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 0 11"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JScrollBar" ) {
|
||||||
|
name: "scrollBar1"
|
||||||
|
"orientation": 0
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 11,growx"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JScrollBar" ) {
|
||||||
|
name: "scrollBar4"
|
||||||
|
"orientation": 0
|
||||||
|
"enabled": false
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 12,growx"
|
||||||
|
} )
|
||||||
}, new FormLayoutConstraints( null ) {
|
}, new FormLayoutConstraints( null ) {
|
||||||
"location": new java.awt.Point( 0, 0 )
|
"location": new java.awt.Point( 0, 0 )
|
||||||
"size": new java.awt.Dimension( 650, 410 )
|
"size": new java.awt.Dimension( 720, 535 )
|
||||||
} )
|
} )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,3 +75,9 @@ Component.focusColor=97c3f3
|
|||||||
|
|
||||||
Label.foreground=008800
|
Label.foreground=008800
|
||||||
Label.disabledForeground=000088
|
Label.disabledForeground=000088
|
||||||
|
|
||||||
|
|
||||||
|
#---- ScrollBar ----
|
||||||
|
|
||||||
|
ScrollBar.track=88ff88
|
||||||
|
ScrollBar.thumb=33737373
|
||||||
|
|||||||
Reference in New Issue
Block a user