Custom scroll bar

* Added PrimaryScrollBar class
* Implemented PrimaryScrollBar in ChatWindow for the ScrollPanes
vertical scroll bar
This commit is contained in:
DieGurke 2019-12-14 19:10:45 +01:00
parent 12b0cc1d0b
commit 4a2d6f913b
2 changed files with 106 additions and 0 deletions

View File

@ -1,5 +1,6 @@
package envoy.client.ui;
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Font;
import java.awt.GridBagConstraints;
@ -252,6 +253,16 @@ public class ChatWindow extends JFrame {
// scrollPane
scrollPane.setForeground(theme.getBackgroundColor());
scrollPane.setBackground(theme.getCellColor());
// scrollPane.getVerticalScrollBar()
// .setBackground(
// new Color(theme.getBackgroundColor().getRed() + 50,
// theme.getBackgroundColor().getGreen() + 50,
// theme.getBackgroundColor().getBlue() + 50));
scrollPane.getVerticalScrollBar().setBackground(theme.getCellColor());
scrollPane.getVerticalScrollBar()
.setUI(new PrimaryScrollBar(5, theme.getInteractableBackgroundColor(),
new Color(theme.getInteractableBackgroundColor().getRGB() - 50),
new Color(theme.getInteractableBackgroundColor().getRGB() + 170)));
// messageEnterTextArea
messageEnterTextArea.setCaretColor(theme.getTypingMessageColor());
messageEnterTextArea.setForeground(theme.getTypingMessageColor());

View File

@ -0,0 +1,95 @@
package envoy.client.ui;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JScrollBar;
import javax.swing.plaf.basic.BasicScrollBarUI;
import envoy.client.Settings;
/**
* Project: <strong>envoy-client</strong><br>
* File: <strong>PrimaryScrollBar.javaEvent.java</strong><br>
* Created: <strong>14.12.2019</strong><br>
*
* @author Maximilian K&auml;fer
* @since Envoy v0.2-alpha
*/
public class PrimaryScrollBar extends BasicScrollBarUI{
private final Dimension d = new Dimension();
private int arcSize;
private Color scrollBarColor;
private Color hoverColor;
private Color draggingColor;
public PrimaryScrollBar(int arcSize, Color scrollBarColor, Color hoverColor, Color draggingColor) {
this.arcSize = arcSize;
this.scrollBarColor = scrollBarColor;
this.hoverColor = hoverColor;
this.draggingColor = draggingColor;
}
@Override
protected JButton createDecreaseButton(int orientation) {
return new JButton() {
private static final long serialVersionUID = 1032443171070235890L;
@Override
public Dimension getPreferredSize() {
return d;
}
};
}
@Override
protected JButton createIncreaseButton (int orientation) {
return new JButton() {
private static final long serialVersionUID = 7575774542623215803L;
@Override
public Dimension getPreferredSize() {
return d;
}
};
}
@Override
protected void paintTrack(Graphics g, JComponent c, Rectangle r) {
}
@Override
protected void paintThumb(Graphics g, JComponent c, Rectangle r) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Color color = null;
JScrollBar sb = (JScrollBar) c;
if (!sb.isEnabled() || r.width > r.height) {
return;
} else if (isDragging) {
color = draggingColor;
} else if (isThumbRollover()) {
color = hoverColor;
} else {
color = scrollBarColor;
}
g2.setPaint(color);
g2.fillRoundRect(r.x + 9, r.y, r.width - 10, r.height, arcSize, arcSize);
g2.setPaint(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getCellColor());
g2.drawRoundRect(r.x + 9, r.y, r.width - 10, r.height, arcSize, arcSize);
g2.dispose();
}
@Override
protected void setThumbBounds(int x, int y, int width, int height) {
super.setThumbBounds(x, y, width, height);
scrollbar.repaint();
}
}