java - 使用 JPanel 和 JLabel 手动创建 JTabbedPane 的选项卡标题

标签 java swing tabs header jtabbedpane

我想创建一个 JTabbedPane,但我想手动创建标题,我创建了一个 JPanelJLabel 我把我的图标和背景颜色,但我不知道如何将其添加到选项卡式 Pane 中。

选项卡式 Pane 有 4 个面板:

   JPanel header = new JPanel();
   header.setSize(100, 50);
   header.setBackground(Color.red);
   JLabel icon_Label = new JLabel(Icon);
   icon_Label.setText("header 1");
   jTabbedPane1.getComponentAt(1).*************?!

最佳答案

我找到了

JPanel panel = new JPanel();
    panel.setBackground(Color.BLUE);
    JLabel title = new JLabel("OK");
    title.setForeground(Color.RED);
    title.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/icons8-boîte-pleine-64.png")));
    title.setText("GESTION A");
    panel.add(title);
   jTabbedPane1.setTabComponentAt(2, panel);

但是标题左右有空格! enter image description here

关于java - 使用 JPanel 和 JLabel 手动创建 JTabbedPane 的选项卡标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59809909/

相关文章:

java - 关于Java GUI和Java控制流的一些疑问

java - 是否可以为 Set<Double>.contains() 设置精度?

java - JComponent 绘制前高度

Xcode 4 首选项 Pane 缺少 "Source Trees"选项卡?

bash - 在多个(新)选项卡中打开现有 Gvim 中的文件

java - 在java中,从字符串中删除重复字符的最有效方法是什么?

java - JOptionPane.showInputDialog() 是否返回不同的字符串

java - addMouseListener 出错

java - 如果在 EDT 线程之外调用 AWT 代码,如何引发异常?

javascript - vueJS如何在不同选项卡显示不同内容