Hi,
I am using JSeparator as horizontal gridline. I want modify the JSeparator's continuous line display to dashed/dotted line.
I am using Gridbag layout for my JPanel.
Since I have to enable auto-resize for JSeparator, I cannot use a fixed length.

I tried overiding paint & modified stroke to display dashed line(used drawPolyLine() method). But here I have to specify a fixed length.
Kindly help me how to achive this?

Recommended Answers

All 3 Replies

I simply want to use JSeperator and want to know how it is implemented if anyone can please help!

Start your own thread. But as a quick answer, see the tutorials, they have one that specifically covers menus and menubars, including separators.

Hi Neha
Sorry so late in replying; somehow I failed to notice you original post.

What you did was a good solution - for the length of the line you can just call getWidth() which you inherit from JSeparator and which tells you the current width (ie the necessary line length) in pixels. Depending on how you implemented it you may need to loop drawing one dash at a time until the desired width is met/exceeded. There's no problem if you draw past the currently visible part of the Graphics, so depending on your application details it could be slightly easier to just draw a line thats "long enough" for the worst case.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.