gpt4 book ai didi

java - 在 JTabbedPane 中拆分标签

转载 作者:行者123 更新时间:2023-12-02 05:00:52 26 4
gpt4 key购买 nike

我需要更改 JTabbedPane 上标签的分布。

我有这个:

enter image description here我想这样做: enter image description here有人可以帮助我吗?

我发布下面的代码:

 tabbedResultsPane = new JTabbedPane(SwingConstants.TOP);

JPanel featurePanel = new JPanel(new GridLayout(TOTAL_FEATURES, 2, 3, 3));
estadoScroll = new JScrollPane(featurePanel,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
lblFeatureHdr = new JLabel[TOTAL_FEATURES];
lblFeature = new JLabel[TOTAL_FEATURES];
for(int i=0; i<TOTAL_FEATURES; i++)
{
lblFeatureHdr[i] = new JLabel(strHeader[i], JLabel.RIGHT);
lblFeatureHdr[i].setOpaque(true);
lblFeatureHdr[i].setBackground(new Color(220,255,220));//.lightGray);

lblFeature[i] = new JLabel("", JLabel.LEFT);
lblFeature[i].setForeground(Color.blue);// black);

featurePanel.add(lblFeatureHdr[i]);
featurePanel.add(lblFeature[i]);
}

最佳答案

定义 4 列 GridLayout(而不是您拥有的 2 列)。

并更正您的代码,为每行添加 2 个标签。

for(int i=0; i<TOTAL_FEATURES; i++)
{
lblFeatureHdr[i] = new JLabel(strHeader[i], JLabel.RIGHT);
lblFeatureHdr[i].setOpaque(true);
lblFeatureHdr[i].setBackground(new Color(220,255,220));//.lightGray);

lblFeature[i] = new JLabel("", JLabel.LEFT);
lblFeature[i].setForeground(Color.blue);// black);

featurePanel.add(lblFeatureHdr[i]);
featurePanel.add(lblFeature[i]);
// add 2 more lables to the same row
JLabel l=new JLabel(strHeader[i], JLabel.RIGHT);
l.setBackground(new Color(220,255,220));//.lightGray);
featurePanel.add(l);
featurePanel.add(new JLabel("", JLabel.LEFT));
}

关于java - 在 JTabbedPane 中拆分标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28297776/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com