在 Java 中创建更高级的元素:Swing 或图像 [英] Creating more advanced elements in Java: Swing or images

查看:23
本文介绍了在 Java 中创建更高级的元素:Swing 或图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Java 中使用 Swing 创建 GUI 时,应该如何创建更高级的元素"?例如,请考虑:

When creating a GUI in Java with Swing, how should more advanced "elements" be created? As an example, consider:

这可以使用 ~10 张图片来完成,具体取决于当前页面或状态.我也确信可以以编程方式执行此操作,但是,考虑到我过去使用 Swing 的经验,我也确信它会大量代码用于相对简单的事情.特别是考虑到这可以用最多 40 行代码在 CSS 中完成.

This could be done using ~10 images depending on the current page or status. I'm also sure that it'd be possible to do this programmatically, however, considering my past experiences with Swing, I'm also sure it'd be a lot of code for something relatively simple. Especially considering this could be done in CSS with max ~40 lines of code.

在这种情况下,是否有其他方法来创建这个元素"?如果没有;什么是首选:图像或 Swing?

In a situation like this, is there any alternative approach to create this "element"? If not; what's preferred: images or Swing?

推荐答案

  1. 您可以使用合适的 Unicode 字形,例如✓—CHECK MARK 或任何数字,

  1. You can use a suitable Unicode glyph, e.g. ✓—CHECK MARK or any digit,

  • 作为标签文本,在此处显示.

作为 GlyphVector,在此处提及.

作为渲染图像,在此处说明.

as a rendered image, illustrated here.

您可以通过实现Icon 接口来获得一个着色的、消除锯齿的圆圈;ColorIcon 就是一个例子.

You can get a tinted, anti-aliased circle by implementing the Icon interface; ColorIcon is an example.

您可以使用 BasciStroke 获得各种实线和虚线,见此处.

You can get a variety of solid and dashed lines using BasciStroke, seen here.

在现有的布局管理器中,FlowLayout 可能就足够了.

Among the stock layout managers, FlowLayout may be adequate.

这篇关于在 Java 中创建更高级的元素:Swing 或图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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