Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-10-2010, 08:33 PM   PM User | #1
Dmor574
New to the CF scene

 
Join Date: Nov 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Dmor574 is an unknown quantity at this point
Need help with JButton not appearing

I'm starting to develop a window that i'll be using in future games that i'll create. This is a customized JFrame which i made undecorated, and created my own borders, and i'm currently adding an exit button.

The problem is this: Currently, the jbutton appears, but if you look down the code to see the bold/underlined statement, it basically adds a PNG image to the jbutton.

This works perfectly, but when I un-comment those lines (or just even the ImageIcon line), the button only appears when the mouse hovers over the JButton. Is this a glitch with swing? because I don't even add the image to the jbutton, and the button still doesn't appear...

if you need some more code, i'll send the code for the frame; thank you.


//adds an exit button in top right corner
public void addExitButton()
{
int panelSize = 30; //size of panel and button
JPanel exitPanel = new JPanel();
exitPanel.setSize(panelSize, panelSize); //panel is a square
exitPanel.setLocation(WIDTH-panelSize-2, 2); //Top Right corner
exitPanel.setBackground(new Color(0,0,0,0)); //makes panel transparent

JButton exitButton = new JButton();
exitButton.setSize(panelSize, panelSize); //button size = panel size
//ImageIcon i = new ImageIcon("images\\ExitButton1.png");
//exitButton.setIcon(i); //get exit image


//exitButton.setBorderPainted(false); //remove button border
exitButton.setBackground(new Color(0,0,0,0)); //makes button transparent

exitButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//if button pressed
Graphics g = getGraphics();
g.setFont(new Font("Times New Roman", Font.ITALIC, 75));
g.setColor(Color.RED);
g.drawString("Exiting...", 175, 175);

try
{
Thread.sleep(250);
}
catch(Exception ex) {}

System.exit(0); //terminates JVM
}
});

exitPanel.add(exitButton);
this.add(exitPanel);
}
Dmor574 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:08 PM.


Advertisement
Log in to turn off these ads.