Gremlin92
@Gremlin92
Целеустремленный

Почему кнопка на весь фрейм?

Юзаю такой код
JFrame frame = new JFrame();
            frame.setLocation(0, 0);
            frame.setSize(300,300);
            JButton button = new JButton();
            button.setSize(100,50);
            button.setLocation(100, 150);
            button.addActionListener(new ActionListener(){
                    @Override
                    public void actionPerformed(ActionEvent e)
                    {
                        frame.dispose();
                    }
                    });
            frame.add(button);
            frame.show();

а кнопка на всю форму:
5f1164923c646547543103.png
  • Вопрос задан
  • 105 просмотров
Решения вопроса 1
Gremlin92
@Gremlin92 Автор вопроса
Целеустремленный
Помогла прослойка в виде панели
JFrame frame = new JFrame();
            frame.setLocation(0, 0);
            frame.setSize(300,300);
            JButton button = new JButton("close");
            button.setSize(100,50);
            button.setLocation(100, 150);
            Dimension dim = new Dimension();
            dim.width = 100;
            dim.height = 50;
            button.setMaximumSize(dim);
            button.addActionListener(new ActionListener(){
                    @Override
                    public void actionPerformed(ActionEvent e)
                    {
                        frame.dispose();
                    }
                    });
            JPanel panel = new JPanel();
            panel.setSize(frame.getSize());
            panel.add(button);
            frame.add(panel);
            frame.show();
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы