-
Anonymous
Почему мой цвет JPanel заполнил весь графический интерфейс окна? Я не знал, что-то не так в коде или компиляторе?
Сообщение
Anonymous »
окно выглядело так:
введите сюда описание изображения
это мой код:
Код: Выделить всё
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class gui2 {
public static void main(String[] args) {
JPanel bluepanel = new JPanel();
bluepanel.setBackground(Color.blue);
bluepanel.setBounds(0, 0, 250, 250);
JPanel greenpanel = new JPanel();
greenpanel.setBackground(Color.green);
greenpanel.setBounds(250, 0, 250, 250);
JPanel redpanel = new JPanel();
redpanel.setBackground(Color.red);
redpanel.setBounds(0, 250, 250, 250);
JFrame frame = new JFrame();
frame.setTitle("what?");
frame.setSize(500,500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.add(bluepanel);
frame.add(greenpanel);
frame.add(redpanel);
}
}
Я пытался добавить новый JPanel или даже установить цвет фона, но это не решило проблему.
Подробнее здесь:
https://stackoverflow.com/questions/789 ... -if-theres
1726579025
Anonymous
окно выглядело так:
введите сюда описание изображения
это мой код:
[code]import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class gui2 {
public static void main(String[] args) {
JPanel bluepanel = new JPanel();
bluepanel.setBackground(Color.blue);
bluepanel.setBounds(0, 0, 250, 250);
JPanel greenpanel = new JPanel();
greenpanel.setBackground(Color.green);
greenpanel.setBounds(250, 0, 250, 250);
JPanel redpanel = new JPanel();
redpanel.setBackground(Color.red);
redpanel.setBounds(0, 250, 250, 250);
JFrame frame = new JFrame();
frame.setTitle("what?");
frame.setSize(500,500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.add(bluepanel);
frame.add(greenpanel);
frame.add(redpanel);
}
}
[/code]
Я пытался добавить новый JPanel или даже установить цвет фона, но это не решило проблему.
Подробнее здесь: [url]https://stackoverflow.com/questions/78994238/why-did-my-color-of-jpanel-fill-up-all-the-window-gui-i-didnt-know-if-theres[/url]