Set size of scroll button in JTabbedPane with SCROLL_TAB_LAYOUT policy
Hello,
I am using JTabbedPane and its has tab layout policy of SCROLL_TAB_LAYOUT. I want to increase the size of the scroll buttons. How I can do that?
I tried to set the size inside tabbepane's ui using the following function:
Code:
protected JButton createScrollButton(int direction)
{
JButton button = super.createScrollButton(direction);
// button.setSize(new Dimension(50,50));
button.setPreferredSize(new Dimension(50, 50));
button.setMinimumSize(new Dimension(50, 50));
button.setMaximumSize(new Dimension(50, 50));
return button;
}
But, it didn't work.
thanks.
Re: Set size of scroll button in JTabbedPane with SCROLL_TAB_LAYOUT policy
The reason it doesn't work is because the scroll button created is a subclass of BasicArrowButton, which returns hard-coded values from it's getPreferredSize and getMinimumSize methods. If you override the getPreferredSize method it should work.
Unfortunately, to do this, you need to create the scroll button yourself, instead of calling the superclass method.
Fortunately, in principle, it shouldn't be difficult:
Code:
return new BasicArrowButton(direction,
UIManager.getColor("TabbedPane.selected"),
UIManager.getColor("TabbedPane.shadow"),
UIManager.getColor("TabbedPane.darkShadow"),
UIManager.getColor("TabbedPane.highlight")) {
public Dimension getPreferredSize() {
return new Dimension(50, 50);
}
};
OK, this is pure guesswork, and it's untested, but if it doesn't work, it's got to be fairly close :rolleyes:
Genius is 1 percent inspiration and 99 percent perspiration. As a result, genius is often a talented person who has simply done all of his homework...
T. Edison
Re: Set size of scroll button in JTabbedPane with SCROLL_TAB_LAYOUT policy
Thank you very very much. It worked.
Re: Set size of scroll button in JTabbedPane with SCROLL_TAB_LAYOUT policy
Re: Set size of scroll button in JTabbedPane with SCROLL_TAB_LAYOUT policy
Hi dude,
There is one issue I was facing after implementing your solution.
BasicArrowButton does not implement UIResource so I was getting two extra tabs.
What I have done to resolve this is I have created my own class which extends BasicArrowButton and implements UIResource.
That works..
Re: Set size of scroll button in JTabbedPane with SCROLL_TAB_LAYOUT policy
OK, thanks for the update :thumb:
The person who says it cannot be done should not interrupt the person doing it...
Chinese Proverb