Java separate components with lines(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 用线条分隔组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java 用线条分隔组件


- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01