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?

Edited by pritaeas: Moved to Java.

5 Years
Discussion Span
Last Post by JamesCherrill

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.

Edited by JamesCherrill

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.