我需要关于JavaSwingforGUI的帮助。我包括 frame.getcontentpane().setBackground(color.cyan);
但帧背景颜色不变。
import javax.swing.*;
import java.awt.*;
public class LoginOne {
private static JLabel lblUsr;
private static JButton btnNext;
private static JTextField txtUsr;
private static JFrame frame;
private static JPanel panel;
public static void main(String[] args) {
frame = new JFrame("Home Page");
frame.setSize(800,600);
frame.getContentPane().setBackground(Color.cyan);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel = new JPanel();
frame.add(panel);
panel.setLayout(null);
lblUsr = new JLabel("Username"); //Username Label
lblUsr.setBounds(10,20,80,25);
panel.add(lblUsr);
txtUsr = new JTextField(20); //Username input field
txtUsr.setBounds(80,20,80,25);
panel.add(txtUsr);
btnNext = new JButton("Next");
btnNext.setBounds(80,90,80,25);
panel.add(btnNext);
frame.setVisible(true);
}
}
1条答案
按热度按时间1szpjjfi1#
使用
panel.setBackground(Color.CYAN);
相反