JLabel中的两个图标? [英] Two icons in a JLabel?

查看:121
本文介绍了JLabel中的两个图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JLabel中有一个图标,如下所示:

I have an icon in a JLabel as shown below:

是否可以在颜色图标和文本之间添加另一个图标(例如代表国家/地区的标志)?例如,我想在红色图标和 US 之间添加一个描绘美国国旗的图标。谢谢!

Is it possible to add another icon (e.g. a flag representing a country) between the color icon and the text? For example, I want to add an icon depicting the U.S. flag between the red icon and US. Thanks!

推荐答案

是的,在容器标签中使用嵌套的JLabel和BoxLayout:

Yes, use nested JLabel with BoxLayout in the container label:

JLabel container = new JLabel();
container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS));
JLabel icon1Label = new JLabel();
JLabel icon2Label = new JLabel();
icon1Label.setIcon(icon1);
icon2Label.setIcon(icon2);
container.add(icon1Label);
container.add(icon2Label);

这篇关于JLabel中的两个图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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