DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2006
    Posts
    2

    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.

  2. #2
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    Did you try the method setIcon() of JButton? this will set your icon to whatever you want whereever you want

  3. #3
    Join Date
    Apr 2006
    Posts
    2
    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

  1. Another Frame Question
    By Micah Nasarow in forum Web
    Replies: 1
    Last Post: 08-24-2001, 07:31 PM
  2. Change Other Apps Icon
    By Guerrier O. in forum VB Classic
    Replies: 6
    Last Post: 06-21-2000, 12:58 PM
  3. Change Other Apps Icon
    By Guerrier O. in forum VB Classic
    Replies: 0
    Last Post: 06-21-2000, 07:56 AM
  4. to change the default icon of a shortcut.
    By ganesh in forum VB Classic
    Replies: 2
    Last Post: 03-29-2000, 12:46 PM
  5. to change the default icon of a shortcut.
    By ganesh in forum VB Classic
    Replies: 0
    Last Post: 03-29-2000, 12:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links