简体   繁体   English

Java的简单GUI界面

[英]A Simple GUI Interface for Java

doing some self study for a simple GUI interface for Java. 为Java的简单GUI界面做一些自学。 Tried to code a simple interface. 试图编写一个简单的界面代码。 Here is the below code: 这是下面的代码:

public void MainPanel() {

    JFrame frame = new JFrame();
    frame.setTitle("Title");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTabbedPane mpt = new JTabbedPane();

    mpt.addTab("Intro", new IntroPanel());
    mpt.addTab("Catalogue", new CataloguePanel());
    mpt.addTab("Order", new OrderPanel());
    mpt.addTab("Track", new TrackPanel());

    JPanel main = new JPanel();
    main.setBackground(Color.white);

    JLabel label1 = new JLabel("Intro");

    main.add(label1);
    frame.add(main);
    frame.add(mpt);       
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

The problem I am currently facing is: If I put frame.add(main) infront of frame.add(mpt) , only the tabs will appear but the the label intro. 我当前面临的问题是:如果将frame.add(main)放在frame.add(main) frame.add(mpt)frame.add(mpt) ,则只会显示选项卡,而标签介绍。 If I put frame.add(mpt) infront of frame.add(main) . 如果我将frame.add(mpt)放在frame.add(mpt) frame.add(main)frame.add(main) Intro will appear but not the tabs. 将显示简介,但不显示选项卡。

Why is this happening? 为什么会这样呢? Why are they overlapping each other? 它们为什么彼此重叠? I did it the same way as some tutorial but to no avail.. 我做了一些教程一样的方法,但无济于事。

Try giving it some other layout. 尝试给它一些其他布局。

eg. 例如。 frame.setLayout(new FlowLayout());

Info: 信息:

According to Java Naming Conventions your method's name should be like public void mainPanel() 根据Java命名约定,您方法的名称应类似于public void mainPanel()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM