Jump to content

Java swing jbutton not editable after being added to frame, why?

btnCard1.add(btnCardLabel1);
btnCard2.add(btnCardLabel2);
btnCard3.add(btnCardLabel3);
btnCard4.add(btnCardLabel4);
btnCard5.add(btnCardLabel5);
btnCard6.add(btnCardLabel6);
//adds the image label to the card, images work fine nothing to see here

 

frame.getContentPane().add(btnCard1);
frame.getContentPane().add(btnCard2);
frame.getContentPane().add(btnCard3);
frame.getContentPane().add(btnCard4);
frame.getContentPane().add(btnCard5);
frame.getContentPane().add(btnCard6);

ADD BUTTONS WITH A JLABEL WHICH HAS AN IMAGE IN IT NAMED "girl.png" TO A JFRAME, RIGHT?

THEN LETS TRY TO EDIT THE BUTTONS AFTERWARDS AND WRITE IT TO FRAME!

frame.getContentPane().remove(btnCard1); //tried with this and with it removed, this just disables the button. pointless to include, but including it if someone suggests I add it
		ImageIcon btnCardIcon1 = new ImageIcon("white.jpg");
		JLabel btnCardLabel1 = new JLabel(btnCardIcon1);
		btnCard1.add(btnCardLabel1);
		frame.getContentPane().add(btnCard1);

DOESN'T WORK!!!

 

WHAT THE HECK IS GOING ON

 

(I can't declare these later, as the user has to actually see white buttons first, and then when they click the white buttons the real image shows up!)

 

Is java swing really incapable of such a thing as simple as clicking a button and having it change the damn properties of the button??

OFF TOPIC: I suggest every poll from now on to have "**CK EA" option instead of "Other"

Link to post
Share on other sites

Add an action listener that changes the picture on the button when it gets clicked?

 

Dont have access to an ide right now (on my phone) but iirc that's how it works.

AMD Ryzen 7800 X3D, MSI B650 Project Zero, Antec C5, Gigabyte RTX 4080 Super Aero

 

Nikon D500 | Nikon 300mm f/4 PF  | Nikon 200-500 f/5.6 | Nikon 50mm f/1.8 | Tamron 70-210 f/4 VCII | Sigma 10-20 f/3.5 | Nikon 17-55 f/2.8 | Tamron 90mm F2.8 SP Di VC USD Macro | Neewer 750II

Link to post
Share on other sites

13 hours ago, Fetzie said:

Add an action listener that changes the picture on the button when it gets clicked?

 

Dont have access to an ide right now (on my phone) but iirc that's how it works.

I tried this!

https://hastebin.com/ijetebadew.java

Look! Look! I tried this! It doesn't matter what I do! It really should be that simple BUT IT DOESNT WORK!!!

 

OFF TOPIC: I suggest every poll from now on to have "**CK EA" option instead of "Other"

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×