From: | Ursula Lee <ursula(dot)lee(at)thales-is(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | How to set the background color of the JPanel in Java Applet? |
Date: | 2003-07-18 08:46:57 |
Message-ID: | 3F17B401.3070309@thales-is.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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);
}
From | Date | Subject | |
---|---|---|---|
Next Message | Shridhar Daithankar | 2003-07-18 08:55:35 | Re: Application & Authentication |
Previous Message | Annabelle Desbois | 2003-07-18 07:27:27 | Re: ERROR: current transaction is aborted, queries ignored |