O
Oxnard
I am extending JApplet. I want the background color of the JApplet to match
the background color of the web page. I found if I:
javax.swing.JLayeredPane jlp = new javax.swing.JLayeredPane();
jlp.setBackground(new java.awt.Color(0xfe,0xfe,0xf2));
setLayeredPane(jlp);
in the init() function I get the background color I'm looking for. However,
do this seems to cause repaint or paint not to be called. What is occuring
is within my JApplet I am creating a JMenuBar with a JMenu and the JMenu has
a couple of JMenuItems. If I select the Menu the MenuItems display however
if I do not select an Item from the Menu the Items do not go away. I would
like a repaint or paint to occur to repaint the JLayeredPane I am using. I
am pretty sure the issue is with the JLayeredPane as if I comment out the
creation and adding of jlp the JApplet repaints as one would expect, however
in this case the color is the default gary color I am trying to get away
from. My question is how can I get the JLayeredPane to redraw?
Here is the current code:
public class t4 extends javax.swing.JApplet {
/** Initializes the applet t2 This function Must be here*/
public void init() {
initComponents();
}
/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
setBackground(new java.awt.Color(0xfe,0xfe,0xf2)); // sets the background of
the JApplet
jlp.setBackground(new java.awt.Color(0xfe,0xfe,0xf2)); // changes the
background color
setLayeredPane(jlp); // makes the JLayeredPane created to the current
JLayeredPane of the JApplet
// Instanisate the objects
jMenuBar1 = new javax.swing.JMenuBar();
jMenuBar1.setBackground(new java.awt.Color(0xfe,0xfe,0xf2));
jMenu1 = new javax.swing.JMenu();
jMenu1.setText("t1");
jMenu1.setBackground(new java.awt.Color(0xfe,0xfe,0xf2));
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem1.setBackground(new java.awt.Color(0xfe,0xfe,0xf2));
jMenuItem1.setText("Go to java.sun.com");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() { // An
Anonymous Inner Class
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenuItem2 = new javax.swing.JMenuItem();
jMenuItem2.setBackground(new java.awt.Color(0xfe,0xfe,0xf2));
jMenuItem2.setText("Go to Oracle");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() { // An
Anonymous Inner Class
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
// add the Items to the Menu jMenu1
jMenu1.add(jMenuItem1);
jMenu1.add(jMenuItem2);
jMenuBar1.add(jMenu1);
// jMenu2.setText("Menu");
// jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
}
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.out.println("here I am");
showStatus("test ");
urlString = getParameter("link_1");
try{
final java.net.URL url = new java.net.URL(urlString);
java.applet.AppletContext context = getAppletContext();
context.showDocument(url,"right");
}catch(java.net.MalformedURLException e){
e.printStackTrace();
}
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.out.println("here I am");
showStatus("test ");
urlString = getParameter("link_2");
try{
final java.net.URL url = new java.net.URL(urlString);
java.applet.AppletContext context = getAppletContext();
context.showDocument(url,"right");
}catch(java.net.MalformedURLException e){
e.printStackTrace();
}
}
private javax.swing.JLayeredPane jlp = new javax.swing.JLayeredPane(); //
creates a JLayeredPane so that the background color can be changed
// Variables declaration - do not modify
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private String urlString;
// End of variables declaration
}
Thanks for your time!
Ox
the background color of the web page. I found if I:
javax.swing.JLayeredPane jlp = new javax.swing.JLayeredPane();
jlp.setBackground(new java.awt.Color(0xfe,0xfe,0xf2));
setLayeredPane(jlp);
in the init() function I get the background color I'm looking for. However,
do this seems to cause repaint or paint not to be called. What is occuring
is within my JApplet I am creating a JMenuBar with a JMenu and the JMenu has
a couple of JMenuItems. If I select the Menu the MenuItems display however
if I do not select an Item from the Menu the Items do not go away. I would
like a repaint or paint to occur to repaint the JLayeredPane I am using. I
am pretty sure the issue is with the JLayeredPane as if I comment out the
creation and adding of jlp the JApplet repaints as one would expect, however
in this case the color is the default gary color I am trying to get away
from. My question is how can I get the JLayeredPane to redraw?
Here is the current code:
public class t4 extends javax.swing.JApplet {
/** Initializes the applet t2 This function Must be here*/
public void init() {
initComponents();
}
/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
setBackground(new java.awt.Color(0xfe,0xfe,0xf2)); // sets the background of
the JApplet
jlp.setBackground(new java.awt.Color(0xfe,0xfe,0xf2)); // changes the
background color
setLayeredPane(jlp); // makes the JLayeredPane created to the current
JLayeredPane of the JApplet
// Instanisate the objects
jMenuBar1 = new javax.swing.JMenuBar();
jMenuBar1.setBackground(new java.awt.Color(0xfe,0xfe,0xf2));
jMenu1 = new javax.swing.JMenu();
jMenu1.setText("t1");
jMenu1.setBackground(new java.awt.Color(0xfe,0xfe,0xf2));
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem1.setBackground(new java.awt.Color(0xfe,0xfe,0xf2));
jMenuItem1.setText("Go to java.sun.com");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() { // An
Anonymous Inner Class
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenuItem2 = new javax.swing.JMenuItem();
jMenuItem2.setBackground(new java.awt.Color(0xfe,0xfe,0xf2));
jMenuItem2.setText("Go to Oracle");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() { // An
Anonymous Inner Class
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
// add the Items to the Menu jMenu1
jMenu1.add(jMenuItem1);
jMenu1.add(jMenuItem2);
jMenuBar1.add(jMenu1);
// jMenu2.setText("Menu");
// jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
}
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.out.println("here I am");
showStatus("test ");
urlString = getParameter("link_1");
try{
final java.net.URL url = new java.net.URL(urlString);
java.applet.AppletContext context = getAppletContext();
context.showDocument(url,"right");
}catch(java.net.MalformedURLException e){
e.printStackTrace();
}
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.out.println("here I am");
showStatus("test ");
urlString = getParameter("link_2");
try{
final java.net.URL url = new java.net.URL(urlString);
java.applet.AppletContext context = getAppletContext();
context.showDocument(url,"right");
}catch(java.net.MalformedURLException e){
e.printStackTrace();
}
}
private javax.swing.JLayeredPane jlp = new javax.swing.JLayeredPane(); //
creates a JLayeredPane so that the background color can be changed
// Variables declaration - do not modify
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private String urlString;
// End of variables declaration
}
Thanks for your time!
Ox