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

问题描述 投票:0回答:1

我想创建一个JTabbedPane,但是我想手动创建标题,我创建了一个JPanelJLabel,在其中放置了Icon和背景色,但是我不知道如何添加它到选项卡式窗格。

选项卡式窗格有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).*************?!
java swing tabs header jtabbedpane
1个回答
0
投票

我找到它

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

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.