Change a button's icon from a different frame


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Change a button's icon from a different frame

Hybrid View

  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 01: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, 08:31 PM
  2. Change Other Apps Icon
    By Guerrier O. in forum VB Classic
    Replies: 6
    Last Post: 06-21-2000, 01:58 PM
  3. Change Other Apps Icon
    By Guerrier O. in forum VB Classic
    Replies: 0
    Last Post: 06-21-2000, 08:56 AM
  4. to change the default icon of a shortcut.
    By ganesh in forum VB Classic
    Replies: 2
    Last Post: 03-29-2000, 01:46 PM
  5. to change the default icon of a shortcut.
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center