I'm working on a UI on Java with Swing, I want to change the scroll button of a JTabbedPane, so I use a new UI (MyTabbedPaneUI) that I create from the extends MetalTabbedPaneUI.
But when I create my JTabbedPanel there are 2 tabs which appear and I don't want them. If I remove them my scroll bar disappear.
The code :
public class MyTabbedPaneUI extends MetalTabbedPaneUI{
private Icon southIcon = new ImageIcon(MyTabbedPaneUI.class.getResource("south.png"));
private Icon northIcon = new ImageIcon(MyTabbedPaneUI.class.getResource("north.png"));
private Icon eastIcon = new ImageIcon(MyTabbedPaneUI.class.getResource("flecheVerte-gauche-20px.png"));
private Icon westIcon = new ImageIcon(MyTabbedPaneUI.class.getResource("flecheVerte-droite-20px.png"));
public static ComponentUI createUI( JComponent x ) {
return new MyTabbedPaneUI();
}
@Override
protected JButton createScrollButton(int direction) {
if ((direction != SOUTH) && (direction != NORTH) && (direction != EAST) && (direction != WEST)) {
throw new IllegalArgumentException("Direction must be one of: " + "SOUTH, NORTH, EAST or WEST");
}
JButton b = new JButton();
//b.setText("");
b.setPreferredSize(new Dimension(eastIcon.getIconWidth(), eastIcon.getIconHeight()));
if (direction == SOUTH) {
b.setIcon(southIcon);
} else if (direction == NORTH) {
b.setIcon(northIcon);
} else if (direction == WEST) {
b.setIcon(westIcon);
} else {
b.setIcon(eastIcon);
}
return b;
}
}