我在JPanel中添加了一个JTabbedPane,我可以使其延伸到边缘,但是JTabbedPane仍然在其周围留下难看的边框。我以为您将边缘与窗口边缘合并。有谁知道如何做到这一点?这是我所看到的图片。



这是我创建布局的方法:

public class MainFrame extends JFrame {
    private static final long serialVersionUID = 6112493789711533870L;
    private final int FRAME_WIDTH = 720;
    private final int FRAME_HEIGHT = 405;

    private JPanel mainLayout;
    GridBagConstraints c = new GridBagConstraints();

    public MainFrame(String t) {
        super(t);
        setSize(FRAME_WIDTH, FRAME_HEIGHT);
        add(createLayout());
    }

    public JPanel createLayout() {
        this.mainLayout = new JPanel(new GridBagLayout());
        JTabbedPane mainTabs = new JTabbedPane();
        mainTabs.setTabPlacement(JTabbedPane.LEFT);

        JComponent projectPanel = makeTextArea();
        mainTabs.addTab("Projects", projectPanel);

        JComponent tasksPanel = makeTextArea();
        mainTabs.addTab("Tasks", tasksPanel);

        JComponent optionsPanel = makeTextArea();
        mainTabs.addTab("Options", optionsPanel);

        c.fill = GridBagConstraints.BOTH;
        c.weightx = 1.0;
        c.weighty = 1.0;
        c.insets = new Insets(0,0,0,0);

        mainLayout.add(mainTabs, c);
        return mainLayout;
    }

    private JScrollPane makeTextArea() {
        JTextArea textArea = new JTextArea();
        textArea.setEditable(true);

        JScrollPane scrollTextArea = new JScrollPane(textArea);
        scrollTextArea.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

        return scrollTextArea;
    }
}

最佳答案

您无法真正删除该边框。它是JTabbedPane UI的一部分。但是,我始终面临的问题恰恰相反:令人欣喜的是,Nimbus的外观是唯一在选项卡页面周围没有边框的外观。因此,如果您真的想避开边界,可以在应用程序启动时运行一次此代码来使用Nimbus:

try {
    UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Throwable t) {
    throw new RuntimeException(t);
}


否则,我建议在组件周围添加一个额外的空边框,以使细边框看起来不那么难看。

编辑:除了上述内容之外,或者尝试通过在makeTextArea()中添加以下内容来删除JScrollPane的边框:

scrollTextArea.setBorder(BorderFactory.createEmptyBorder());


我现在看到的是:http://i.stack.imgur.com/afr8n.png

关于java - JTabbedPane不会填满整个JPanel,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20288577/

10-11 15:59