A
A
Anton @ Lyalin2017-02-25 09:09:37
Java
Anton @ Lyalin, 2017-02-25 09:09:37

Why in the place of the window piece?

A piece comes out in place of a full-fledged window. Displays items incorrectly.

public FrameSetting(){
        setTitle("Настройки");
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setSize(500, 600);
        setLocationRelativeTo(null);

        JPanel();

        revalidate();
        setVisible(true);
    }

    private void JPanel(){
        JPanel jPanel = new JPanel();
        jPanel.setBorder(BorderFactory.createTitledBorder("Источники"));

        JCheckBox jCheckBoxWiki = new JCheckBox("Википедиа");

        jCheckBoxWiki.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                System.out.println("Вики");
            }
        });

        JCheckBox jCheckBoxOne = new JCheckBox("Второй сайт");

        jCheckBoxOne.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                System.out.println("второй");
            }
        });

        JCheckBox jCheckBoxTwo = new JCheckBox("Третий сайт");

        jCheckBoxTwo.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                System.out.println("третий");
            }
        });

        JPanel jPanelTwo = new JPanel();
        jPanelTwo.setBorder(BorderFactory.createTitledBorder("Что то еще"));

        jPanel.add(jCheckBoxWiki);
        jPanel.add(jCheckBoxOne);
        jPanel.add(jCheckBoxTwo);

        getContentPane().add(jPanel);
        getContentPane().add(jPanelTwo);
        pack();
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question