Problem inserting JTextField into JPanel that is inside JTabbedPane [closed]

1

I have a Swing application where the main window is composed of a JtabbedPane that contains some classes that extend JPanel [ViewPrincipal, ViewCadastro, ViewReport, etc ...].

When I add JLabels and JButtons, they appear and windows work normally, but when I instantiate a JTextField or JTextArea within one of these classes that extend JPanel , JTabbedPanel buga and nothing appears. >

If you try this.setLayout (null) JTabbedPane and JPanels work, but no internal components of the JPanels appear. I feel that setting Layout null is very ugly.

What could be happening?

Putting as few things as possible into the ViewCadastro code we have:

public class ViewCadastro extends JPanel{

        public ViewCadastro(){
            this.gettingStart();
        }

        public void gettingStart(){
            this.setBackground(Color.lightGray);    

            this.painelHeader = new JPanel();       
            this.painelHeader.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
            this.painelActions = new JPanel();
            this.painelActions.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));

            this.labTitulo = new JLabel("Titulo: ");
            this.painelHeader.add(labTitulo);
            //this.txTitulo = new JTextField();
            //this.painelHeader.add(txTitulo);

            this.btnAdicionarFilme = new JButton("Add");        

            this.painelActions.add(btnAdicionarFilme);
            this.add(painelHeader);
            this.add(painelActions);    

        }


        private JButton btnAdicionarFilme;
        private JPanel painelHeader;
        private JPanel painelActions;
        public JLabel labTitulo;
        public JTextField txTitulo; 
}

If you take the comments, it's all over.

And the Main View:

public class View extends JFrame{


    public View(Control controller){
        this.setCtrl(controller);
        this.gettingStart();
    }


    public void gettingStart(){
        this.setVisible(true);
        this.setResizable(false);
        this.setSize(1000,500);


        tabs = new JTabbedPane();
        painelPrincipal = new ViewPrincipal();
        painelCadastro = new ViewCadastro();
        painelRelatorios = new ViewRelatorios();


        //Adicionando paineis

        tabs.add("Principal",painelPrincipal);
        tabs.add("Cadastros",painelCadastro);
        tabs.add("Relatórios",painelRelatorios);

        this.add(tabs);
    }

    private Control ctrl;   
    private ViewCadastro painelCadastro;
    private ViewRelatorios painelRelatorios;
    private ViewPrincipal painelPrincipal;
    private JTabbedPane tabs;
}

The main control:

public class Control {

    private View viewer;

    public Control(){
        setViewer(new View(this));
    }

    public View getViewer() {
        return viewer;
    }

    public void setViewer(View viewer) {
        this.viewer = viewer;
    }
}

Pulled by main pattern:

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new Control();

    }

}
    
asked by anonymous 21.04.2017 / 21:38

1 answer

1

PROBLEM SOLVED:

In the main View (not where I instantiate the JTextField, but in the class that expands the JFrame) I set the JFrame '.setVisible (true);' at the start of the window. already solved the problem.

Current code:

public class View extends JFrame{


    public View(Control controller){
        this.setCtrl(controller);
        this.gettingStart();
    }


    public void gettingStart(){



        tabs = new JTabbedPane();
        painelPrincipal = new ViewPrincipal();
        painelCadastro = new ViewCadastro();
        painelRelatorios = new ViewRelatorios();


        //Adicionando paineis

        tabs.add("Principal",painelPrincipal);
        tabs.add("Cadastros",painelCadastro);
        tabs.add("Relatórios",painelRelatorios);

        this.add(tabs);

        this.setVisible(true);
        this.setResizable(false);
        this.setSize(1000,500);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    private Control ctrl;   
    private ViewCadastro painelCadastro;
    private ViewRelatorios painelRelatorios;
    private ViewPrincipal painelPrincipal;
    private JTabbedPane tabs;

    public Control getCtrl() {
        return ctrl;
    }

    public void setCtrl(Control ctrl) {
        this.ctrl = ctrl;
    }
}
    
21.04.2017 / 23:04