Separate Java components with lines

I am learning some GUI stuff in Java and I think Im missing something here. I have some components vertically listed using BoxLayout, for example, some JButtons that are higher than others. Now I want to separate them from the line between them. Should I use the Graphics library or is there some Swing way to split the components into a string?

Turning directly to the question: how to draw a line for separating components (for example, JButtons) and which is the recommended way to do it?

Thanks!

+4
source share
2 answers

JSeparator shown here is commonly used in this context. It works well with most layouts. Also, consider How to use borders .

Addendum: The JSeparator UI JSeparator for this Look and Feel, often modeled by BasicSeparatorUI , is especially simple. The paint() implementation draws a line with one pixel in the color foreground and a neighboring one pixel line in the background color. The lines have a width (or high), since the boundaries of the components depend on the orientation. The layout manager determines the spacing, so you'll want to see the visual guide for layout managers .

+10
source

JSeparator returns weird hints for size, the most problematic bit for maximizing LayoutManager like BoxLayout is its unlimited max, see also the recent discussion (as for vertical dividers, same for horizontal, though)

+3
source

All Articles