-
Change a button's icon from a different frame
Forgotten my old username and password! :| I also tried to search on the forums for this and it's of little help.
Anyhow, I am making a paint program for my project at uni. I have a panel (in a frame) that has buttons on them. Each button loads up a frame.
I made each frame has their own set of buttons so...
Tools button will open ToolsFrame which contains Pencil button, Paintbrush, Circle, etc.
What I want to do is change the Tools button icon so that it reflects whatever the user chose in the ToolsFrame. Is there a simple way of doing this?
e.g.
I set the buttons up like...
JButton toolsBtn = new JButton("images/tools.JPG");
Pressing toolsBtn will make a new ToolsFrame object:
public void actionPerformed(ActionEvent e)
{
if("tools".equals(e.getActionCommand()))
{
tools = new ToolsFrame();
tools.show();
tools.setLocationRelativeTo(this);
tools.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
}
ToolsFrame is a whole class extending JFrame and implementing ActionListener. The buttons in ToolsFrame are setup just like the toolsBtn above:
JButton paintbrushBtn = new JButton("images/paintbrush.JPG");
Pressing any button in ToolsFrame will close the window.
Last edited by Chi; 04-08-2006 at 12:53 PM.
-
Did you try the method setIcon() of JButton? this will set your icon to whatever you want whereever you want
-
ah right...lol. I wondered why it didn't work - i didn't put in any event listeners to actually invoke setIcon(). that was simpler than expected tbh. lol.
Similar Threads
-
By Micah Nasarow in forum Web
Replies: 1
Last Post: 08-24-2001, 07:31 PM
-
By Guerrier O. in forum VB Classic
Replies: 6
Last Post: 06-21-2000, 12:58 PM
-
By Guerrier O. in forum VB Classic
Replies: 0
Last Post: 06-21-2000, 07:56 AM
-
By ganesh in forum VB Classic
Replies: 2
Last Post: 03-29-2000, 01:46 PM
-
By ganesh in forum VB Classic
Replies: 0
Last Post: 03-29-2000, 01:10 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|