CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2000
    Posts
    43

    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.

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    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

    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
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Jul 2000
    Posts
    43

    Re: Set size of scroll button in JTabbedPane with SCROLL_TAB_LAYOUT policy

    Thank you very very much. It worked.

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Set size of scroll button in JTabbedPane with SCROLL_TAB_LAYOUT policy

    Cool!
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  5. #5
    Join Date
    Apr 2009
    Posts
    1

    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..

  6. #6
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Set size of scroll button in JTabbedPane with SCROLL_TAB_LAYOUT policy

    OK, thanks for the update

    The person who says it cannot be done should not interrupt the person doing it...
    Chinese Proverb
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured