[java] japplet display not displaying buttons??
i have a simple program which displays buttons at the bottom. is it just me or are the buttons not showing up!?? i have to randomly hover over the buttons and click them for them to show up. this makes no sense. go to www.geocities.com/dwu03 - the second applet thats not centered is this one. i have no clue why it isn't showing up
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Editor extends JApplet implements ActionListener
{
private JTextArea textArea;
private JButton saveButton, loadButton;
public void init() {
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
Container c = this.getContentPane();
c.setLayout(new BorderLayout());
textArea = new JTextArea(20, 20);
JScrollPane scrollPane = new JScrollPane(textArea,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
JPanel buttons = new JPanel();
saveButton = new JButton("Save");
loadButton = new JButton("Load");
buttons.add(loadButton);
buttons.add(saveButton);
c.add(scrollPane, "Center");
c.add(buttons, "South");
}
catch(Exception e) {}
}
public void paint(Graphics g) {
}
public void actionPerformed(ActionEvent e) {
}
}
[edited by - lineage on July 28, 2003 8:09:40 PM]
It''s not just you. I''ve had similar problems. What I usually do is stay away from panels as much as possible. They give me a lot of trouble, especially with guis.
the weird thing is, i used a billion panels and the exact same technique in the applet that showed up perfectly fine. i know there's usually a repainting problem, but im having a problem with just initializing. -___-
[edited by - lineage on July 28, 2003 8:46:33 PM]
[edited by - lineage on July 28, 2003 8:46:33 PM]
Your problem is that you are overriding paint(Graphics g) in your applet, but not doing anything with it. You should not override paint unless you are going to be doing some custom painting. Then if you do override paint, you have to call paint for JApplet so that it can draw all of its components.
You can call the super.paint anywhere in there, but you must call it if you want JButtons etc.. to be drawn.
First make it work,
then make it fast.
--Brian Kernighan
"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book
public void paint(Graphics g) { . . custom painting code . super.paint(g);}
You can call the super.paint anywhere in there, but you must call it if you want JButtons etc.. to be drawn.
First make it work,
then make it fast.
--Brian Kernighan
"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement