标题中的图标和顺序标题 [英] Icon in titledBorder title

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

问题描述

是否可以在 titledBorder 的标题中放置一个图标,例如以下代码:

<预><代码>导入 java.awt.GridLayout;导入 javax.swing.JFrame;导入 javax.swing.JLabel;导入 javax.swing.JPanel;导入 javax.swing.border.TitledBorder;公共类 TitledExample 扩展 JPanel {公共标题示例(){超级(真);this.setLayout(new GridLayout(1, 1, 5, 5));JLabel label = new JLabel("标题边框");label.setHorizo​​ntalAlignment(JLabel.CENTER);TitledBorder titled = new TitledBorder("这里是图片吗?? 标题");label.setBorder(title);添加(标签);}

谢谢,干杯

解决方案

这可能不是你想要的,但也许是一个不错的

TitledBorder titled = BorderFactory.createTitledBorder("\u2615");titled.setTitleFont(new Font(Font.Dialog, Font.PLAIN, 32));titled.setTitleColor(Color.blue);label.setBorder(title);

Hi is it possible to place an icon in the title of a titledBorder for example the following code:


import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

public class TitledExample extends JPanel {

  public TitledExample() {
    super(true);

    this.setLayout(new GridLayout(1, 1, 5, 5));

    JLabel label = new JLabel("Titled Border");
    label.setHorizontalAlignment(JLabel.CENTER);

    TitledBorder titled = new TitledBorder("Image here ?? Title");
    label.setBorder(titled);

    add(label);
  }

Thanks , Cheers

解决方案

It's probably not what you want, but maybe a nice Unicode™ glyph or two would do.

Addendum: @rhu's approach is preferable, but I couldn't resist trying this:

TitledBorder titled = BorderFactory.createTitledBorder("\u2615");
titled.setTitleFont(new Font(Font.Dialog, Font.PLAIN, 32));
titled.setTitleColor(Color.blue);
label.setBorder(titled);

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

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