JTabbedPane Tabs are not visible

0

I am creating a JTabbedPane with several JPanels, but at the time of starting the program the 4 tabs are not shown, and I can not understand the reason.

I hope someone can give me a hand to understand why.

package View;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.FlowLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.border.EmptyBorder;

import javax.swing.JList;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.util.Set;
import java.awt.event.ActionEvent;

public class AdminUI extends JFrame {

    private JPanel contentPane;
    private JTextField textFieldTopic;
    private JTextField textFieldUsername;
    private JList listWriteTopics;
    private JList listReadTopics;

    private static String lastUserNameLoadedTopicAccessRules;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    AdminUI frame = new AdminUI();
                    frame.setTitle("AdminUI");
                    frame.setVisible(true);

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public AdminUI() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 574, 512);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        JPanel panelRegisterUsers = new JPanel();

        JPanel panelRegisterClients = new JPanel();

        JPanel panelModifyUserData = new JPanel();

        JPanel panelPolicies = new JPanel();

        JTabbedPane tabbedPane = new JTabbedPane();
        tabbedPane.addTab("Register Users", panelRegisterUsers);
        tabbedPane.addTab("Register Users", panelRegisterClients);

        getContentPane().add(tabbedPane);

    }

}
    
asked by Bryan Romero 15.10.2018 в 21:38
source

1 answer

1

You must bear in mind that when a container does not have a layout defined contentPane.setLayout(null); , all its components must have a specified size explicitly, either with a setSize() or a setBounds() .

Knowing this, the reason you do not see the JTabbedPane is that it does not have an established size. It only remains to indicate, for example, with:

tabbedPane.setBounds(0,0,getWidth(),getHeight());
    
answered by 15.10.2018 / 22:23
source