mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 15:27:16 -06:00
Slider:
- compute useful baseline for horizontal orientation so that the track is vertically centered - no baseline for vertical orientation
This commit is contained in:
@@ -18,6 +18,7 @@ package com.formdev.flatlaf.ui;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
@@ -143,6 +144,22 @@ public class FlatSliderUI
|
|||||||
return new FlatTrackListener();
|
return new FlatTrackListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBaseline( JComponent c, int width, int height ) {
|
||||||
|
if( c == null )
|
||||||
|
throw new NullPointerException();
|
||||||
|
if( width < 0 || height < 0 )
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
|
||||||
|
// no baseline for vertical orientation
|
||||||
|
if( slider.getOrientation() == JSlider.VERTICAL )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// compute a baseline so that the track is vertically centered
|
||||||
|
FontMetrics fm = slider.getFontMetrics( slider.getFont() );
|
||||||
|
return trackRect.y + Math.round( (trackRect.height - fm.getHeight()) / 2f ) + fm.getAscent() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getPreferredHorizontalSize() {
|
public Dimension getPreferredHorizontalSize() {
|
||||||
return UIScale.scale( super.getPreferredHorizontalSize() );
|
return UIScale.scale( super.getPreferredHorizontalSize() );
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package com.formdev.flatlaf.jideoss.ui;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
@@ -141,6 +142,22 @@ public class FlatRangeSliderUI
|
|||||||
disabledThumbBorderColor = null;
|
disabledThumbBorderColor = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBaseline( JComponent c, int width, int height ) {
|
||||||
|
if( c == null )
|
||||||
|
throw new NullPointerException();
|
||||||
|
if( width < 0 || height < 0 )
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
|
||||||
|
// no baseline for vertical orientation
|
||||||
|
if( slider.getOrientation() == JSlider.VERTICAL )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// compute a baseline so that the track is vertically centered
|
||||||
|
FontMetrics fm = slider.getFontMetrics( slider.getFont() );
|
||||||
|
return trackRect.y + Math.round( (trackRect.height - fm.getHeight()) / 2f ) + fm.getAscent() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getPreferredHorizontalSize() {
|
public Dimension getPreferredHorizontalSize() {
|
||||||
return UIScale.scale( super.getPreferredHorizontalSize() );
|
return UIScale.scale( super.getPreferredHorizontalSize() );
|
||||||
|
|||||||
Reference in New Issue
Block a user