Java 用线条分隔组件 [英] Java separate components with lines

查看:29
本文介绍了Java 用线条分隔组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习一些关于 Java 的 GUI 东西,我想我在这里遗漏了一些东西.我有一些使用 BoxLayout 垂直列出的组件,例如一些 JButtons 一个在另一个之上.现在我想将它们分开,在它们之间画一条线.我必须使用图形库还是有一些 Swing 方法可以用线分隔组件?

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?

直奔问题:如何画一条线来分隔组件(例如 JButtons),推荐的做法是什么?

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?

谢谢!

推荐答案

JSeparator,显示 这里,通常用于这种情况.它适用于大多数布局.另外,请考虑 如何使用边框.

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

附录:给定外观的 JSeparator UI 委托感觉,通常仿照 BasicSeparatorUI,特别简单.它的 paint() 实现以前景色绘制一像素线,并以背景色绘制相邻的一像素线.这些线与组件的边界一样宽(或高),具体取决于方向.布局管理器确定间距,因此您需要查看 布局管理器的可视化指南.

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.

这篇关于Java 用线条分隔组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆