[#2358] Update basic slider UI for dark mode
This commit is contained in:
parent
811ea5044e
commit
c6ab31b4e5
@ -1,5 +1,8 @@
|
||||
package net.sf.openrocket.gui.components;
|
||||
|
||||
import net.sf.openrocket.gui.util.GUIUtil;
|
||||
import net.sf.openrocket.gui.util.UITheme;
|
||||
|
||||
import javax.swing.BoundedRangeModel;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.plaf.basic.BasicSliderUI;
|
||||
@ -27,7 +30,11 @@ public class BasicSlider extends JSlider {
|
||||
setOrientation(orientation);
|
||||
setInverted(inverted);
|
||||
setFocusable(false);
|
||||
setUI(new BasicSliderUI(this));
|
||||
if (UITheme.isLightTheme(GUIUtil.getUITheme())) {
|
||||
setUI(new BasicSliderUI(this));
|
||||
} else {
|
||||
setUI(new DarkBasicSliderUI(this));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
package net.sf.openrocket.gui.components;
|
||||
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.plaf.basic.BasicSliderUI;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
/**
|
||||
* BasicSliderUI for dark theme UI.
|
||||
*/
|
||||
public class DarkBasicSliderUI extends BasicSliderUI {
|
||||
private static final Color trackColor = new Color(159, 159, 159);
|
||||
private static final Color thumbColor = new Color(82, 82, 82);
|
||||
private static final Color thumbBorderColor = new Color(166, 166, 166);
|
||||
|
||||
public DarkBasicSliderUI(JSlider b) {
|
||||
super(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintTrack(Graphics g) {
|
||||
g.setColor(trackColor);
|
||||
super.paintTrack(g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintThumb(Graphics g) {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
Rectangle thumbBounds = thumbRect;
|
||||
int w = thumbBounds.width;
|
||||
int h = thumbBounds.height;
|
||||
|
||||
int borderInset = 2; // Adjust this value to change the border thickness
|
||||
|
||||
// Draw the border
|
||||
g2d.setColor(thumbBorderColor);
|
||||
g2d.fillRect(thumbBounds.x, thumbBounds.y, w, h);
|
||||
|
||||
// Draw the thumb fill
|
||||
g2d.setColor(thumbColor);
|
||||
g2d.fillRect(
|
||||
thumbBounds.x + borderInset - 1,
|
||||
thumbBounds.y + borderInset - 1,
|
||||
w - 2 * borderInset + 1,
|
||||
h - 2 * borderInset + 1
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user