Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I decorate the scroll bar? #103

Closed
UltraBurstXD opened this issue May 19, 2020 · 5 comments
Closed

How can I decorate the scroll bar? #103

UltraBurstXD opened this issue May 19, 2020 · 5 comments
Milestone

Comments

@UltraBurstXD
Copy link

Hi JFormDesigner,

I wanted to know how can I decorate the scroll bar.

@DevCharly
Copy link
Collaborator

Don't know what you mean.
Can you provide more details?

If you want arrow buttons or wider scroll bars, see:
https://www.formdev.com/flatlaf/customizing/#scrollbar

@UltraBurstXD
Copy link
Author

UltraBurstXD commented May 19, 2020

I mean changing the shape and decorate the scroll bar like this:

Screenshot from 2020-05-19 18-24-09

That above is Ubuntu's scroll bar
I don't want to make it to be like that... It was only a prototype.

@DevCharly
Copy link
Collaborator

You can subclass FlatScrollBarUI and implement own painting methods.

Here is a working example that paints round thumbs:

public class MyFlatScrollBarUI
	extends FlatScrollBarUI
{
	public static ComponentUI createUI( JComponent c ) {
		return new MyFlatScrollBarUI();
	}

	@Override
	protected void paintThumb( Graphics g, JComponent c, Rectangle thumbBounds ) {
		if( thumbBounds.isEmpty() || !scrollbar.isEnabled() )
			return;

		FlatUIUtils.setRenderingHints( (Graphics2D) g );

		int arc = Math.min( c.getWidth(), c.getHeight() ) - 2;
		g.setColor( thumbColor );
		g.fillRoundRect( thumbBounds.x + 1, thumbBounds.y + 1, thumbBounds.width - 2, thumbBounds.height - 2, arc, arc );
	}
}

Unfortunately it is currently not possible to paint the thumb in a darker color when the mouse is over it because the hover field is private. I'll change that for the next version.
The class must be public.

Then register the class in main after installing FlatLaf with:

UIManager.put( "ScrollBarUI", "com.myproject.MyFlatScrollBarUI" );

This looks like:
image

Anyway, I'm open to support different scrollbar styles out of the box.
Any suggestions are welcome 😉

DevCharly added a commit that referenced this issue May 19, 2020
@UltraBurstXD
Copy link
Author

Thanks, DevCharly.

DevCharly added a commit that referenced this issue May 23, 2020
DevCharly added a commit that referenced this issue May 23, 2020
…se they are given for vertical orientation (issue #103)
@DevCharly DevCharly added this to the 0.36 milestone May 23, 2020
@DevCharly
Copy link
Collaborator

Since FlatLaf 0.36 it is possible to use different styles for scroll bars.
See https://www.formdev.com/flatlaf/customizing/#scrollbar_style

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants