0

像这样!

在此处输入图像描述

并且setOpaque(false);inJTabbedPane没有工作。

有人会帮我吗?

我的代码的一部分:

      for (int x=1; x<6; x++){
        newsPanel[x]=new JPanel();
        newsPanel[x].add(newspicLabel[x]);

        NewsTab.addTab("", Controlbtn, newsPanel[x]);
        }

      NewsTab.setTabPlacement(JTabbedPane.RIGHT);
      NewsTab.setOpaque(false);

非常感谢您!!!


我已经完成了 JTabbedPane,但我想像这样将标签按钮放在 JTabbedPane(Panel) 中 ---在此处输入链接描述

4

1 回答 1

2

这是一个示例代码。

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JToggleButton;


public class SidePane extends JPanel {

    Color c[] = {Color.RED, Color.CYAN, Color.BLACK, Color.BLUE, Color.YELLOW};


    public SidePane() {

        setLayout(new BorderLayout(10, 10));
        ButtonGroup group = new ButtonGroup();
        JToggleButton[] buttons = new JToggleButton[5];
        JPanel leftTop = new JPanel(new GridLayout(buttons.length, 1, 10, 10));
        leftTop.setOpaque(false);
        JPanel left = new JPanel();
        left.setOpaque(false);
        for (int i = 0; i < buttons.length; i++) {
            buttons[i] = new JToggleButton(i + "");
            group.add(buttons[i]);
            leftTop.add(buttons[i]);
            buttons[i].addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    JOptionPane.showMessageDialog(SidePane.this, ((JToggleButton)e.getSource()).getText()); // Write whatever you like.
                }
            });
        }
        buttons[0].setSelected(true);
        left.add(leftTop);
        add(left, "East");
        setBackground(Color.red);
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("My Side Pane");
        frame.add(new SidePane());
        frame.setSize(600, 600);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}
于 2013-04-19T20:08:09.693 回答