Olá pessoal , estou quebrando a cabeça aqui para saber como faço um scroll horizontal personalizado. Vou explicar melhor meu problema. Eu estou fazendo um JScrollBar novinho com o seguinte codigo:
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JScrollBar;
public class GSScrollBar extends JScrollBar {
public GSScrollBar(int type){
super();
setUI(new GSScrollBarUI(1));
}
onde eu seto uma nova skin para meu scroll bar fazendo com que o GSScrollBarUI extenda BasicScrollBar , da seguinte maneira:
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
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;
public class GSScrollBarUI extends BasicScrollBarUI {
int type;
public GSScrollBarUI(int type) {
this.type=type;
}
@Override
protected JButton createIncreaseButton(int orientation)
{
return new GSScrollCornerButton(2);
}
protected JButton createDecreaseButton(int orientation){
return new GSScrollCornerButton(1);
}
@Override
protected void paintThumb(final Graphics g, final JComponent c, final Rectangle thumbBounds) {
Graphics2D g2 = (Graphics2D)g;
g2.translate(thumbBounds.x, thumbBounds.y);
//g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(Color.BLACK);
GradientPaint p = new GradientPaint(
thumbBounds.width / 2-8,thumbBounds.y,new Color(1,1,1,1f),thumbBounds.width / 2+8,thumbBounds.y,new Color(0x5a7ebd)
);
g2.setPaint(p);
//Define first shadow's half
g2.fillRect(
thumbBounds.width / 2-8,0,
(thumbBounds.width / 2+8)/2,thumbBounds.height
);
GradientPaint p2 = new GradientPaint(
thumbBounds.width / 2-8,thumbBounds.height,new Color(0x5a7ebd),thumbBounds.width / 2+8,thumbBounds.height,new Color(1,1,1,1f)
);
g2.setPaint(p2);
//Define second shadow's half
g2.fillRect(
(thumbBounds.width / 2+8)/2,0,
thumbBounds.width / 2+8,thumbBounds.height
);
g2.setPaint(new Color(0xcccccc));
g2.drawRect(
thumbBounds.width / 2-8,0,
thumbBounds.width / 2+8,thumbBounds.height
);
/*
if (isThumbRollover()) {
g2.setPaint(new Color(0x000000));
g2.drawRect(
thumbBounds.width / 2-8,0,
thumbBounds.width / 2+8,thumbBounds.height
);
} */
g2.translate(-thumbBounds.x, -thumbBounds.y);
}
@Override
protected void paintTrack(final Graphics g, final JComponent c, final Rectangle trackBounds) {
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
GradientPaint p = new GradientPaint(
trackBounds.width / 2-12,trackBounds.y,new Color(0xcccccc),trackBounds.width / 2+12,trackBounds.y,new Color(1,1,1,1f)
);
g2.setPaint(p);
//Define shadow dimensions
g2.fillRect(
trackBounds.width / 2-8,
trackBounds.y,
trackBounds.width / 2+8,
trackBounds.height
);
if (this.trackHighlight == BasicScrollBarUI.DECREASE_HIGHLIGHT) {
this.paintDecreaseHighlight(g);
} else if (this.trackHighlight == BasicScrollBarUI.INCREASE_HIGHLIGHT) {
this.paintIncreaseHighlight(g);
}
}
}
O Problema é que quando eu seto esse setUI no JScrollBar ele automaticamente faz com o meu ScrollBar Horizontal se torne vertical, alguem sabe como setar o BasicScrollBarUI para que ele fique no padrão horizontal ???
Obrigado