Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java separate components with lines

I am learning some GUI stuff on Java and I think Im missing something here. I have some components vertically listed using BoxLayout, such as some JButtons one above other. Now I want to separate them drawing a line between them. Do I have to use the Graphics library or is there some Swing way to separate the components with a line?

Going straight to the question: How to draw a line to separate components (such as JButtons) and which is the recommended way of doing it?

Thanks!

like image 881
johnsmith Avatar asked Dec 13 '22 08:12

johnsmith


1 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 delegate for a given Look & Feel, often modeled on BasicSeparatorUI, is particularly simple. It's paint() implementation draws a one pixel line in the foreground color and an adjacent one pixel line in the background color. The lines are as wide (or high) as the component's bounds, depending on orientation. The layout manager determines the spacing, so you'll want to review A Visual Guide to Layout Managers.

like image 122
trashgod Avatar answered Dec 14 '22 22:12

trashgod