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

查看:145
本文介绍了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.

附录:给定Look& amp;的 JSeparator UI委托感觉,通常以 <$ c为蓝本$ c> 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天全站免登陆