How to set the background color of the JPanel in Java Applet? - Mailing list pgsql-general
From | Ursula Lee |
---|---|
Subject | How to set the background color of the JPanel in Java Applet? |
Date | |
Msg-id | 3F17B401.3070309@thales-is.com Whole thread Raw |
Responses |
Re: How to set the background color of the JPanel in Java Applet?
Re: How to set the background color of the JPanel in Java |
List | pgsql-general |
Hi all, Any idea on how to set the background color of the JPanel in Java Applet? A few questions here: 1. I have 3 panels on the JAVA applet, one for 2 buttons, one for user_id label and read text, one for password label and read text. In fact, I don't think I need 3 panels, but once I put everything into the same panel, they all collapse on the same line. Question: Any idea on how to display them correctly, I just want a normal display like: User_id .............. Password ................ <Logon button> <Cancel Button> All displayed at the botton. 2. My applet now has white background color, and I have an image picture on it, but the rest of the space are still white. I am unable to use the function 'setBackground'. Any idea on how to change the color? 3. How to make the whole panel bigger to display on HTML? Here is a portion of my code: import javax.swing.*; import java.applet.*; import java.awt.*; import java.awt.event.*; import java.net.*; import java.util.*; import java.text.*; public class login extends JApplet implements ActionListener { public String getUID; public String getPWD; Image pic; private Label L_UID = new Label("User ID: "); private TextField UID = new TextField(20); private Label L_PWD = new Label("Password: "); private TextField PWD = new TextField(20); private Button loginButton = new Button("Logon"); private Button cButton = new Button("Cancel"); private Button quitButton = new Button("Quit"); // setup display public void init() { Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); JLabel label = new JLabel(getParameter("gretting"), SwingConstants.CENTER); label.setFont(new Font("TimesRoman", Font.BOLD, 18)); contentPane.add(label, "Center"); PWD.setEchoChar('*'); pic = getImage(getDocumentBase(), "pic.gif"); loginButton.addActionListener(this); cButton.addActionListener(this); quitButton.addActionListener(this); JPanel panel1 = new JPanel(); panel1.add(L_UID, "Left"); panel1.add(UID, "Left"); contentPane.add(panel1, BorderLayout.NORTH); panel1.setBackground(Color.gray); JPanel panel2 = new JPanel(); panel2.add(L_PWD, "Center"); panel2.add(PWD, "Center"); contentPane.add(panel2, BorderLayout.CENTER); panel2.setBackground(Color.gray); JPanel panel3 = new JPanel(); panel3.add(loginButton, "South"); panel3.add(cButton, "South"); panel3.add(quitButton, "South"); contentPane.add(panel3, BorderLayout.SOUTH); panel3.setBackground(Color.gray); resize(300, 300); } public void paint(Graphics g) { g.drawImage(pic, 0, 70, 400, 300, this); }
pgsql-general by date: