DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2004
    Posts
    2

    JButton with action and icon but no text

    Hi, I'm doing the bog standard text editor thing and want to make a toolbar that uses actions that I have already defined in the menus. The menus have actions, such as:

    cutAction = new DefaultEditorKit.CutAction();

    and I'm using the Sun code to create an imageicon for the button, but the button keeps on having the text from the action on it as well, which I don't want. My button code is:

    ImageIcon copyIcon = createImageIcon ("images/copy.gif", "Copy"); // createImageIcon is a method 'borrowed' from Sun
    copyButton = new JButton("");
    copyButton.setText("");
    copyButton.setAction(copyAction);
    copyButton.setIcon(copyIcon);
    copyButton.setMnemonic(KeyEvent.VK_C);
    copyButton.setToolTipText("Copy selected text");
    toolBar.add(copyButton);

    Any ideas on how to prevent the text 'Copy_to_clipboard' appearing on the button with the imageicon?

    TIA

  2. #2
    Join Date
    Jul 2004
    Posts
    40
    I am not too sure if this will solve your problem, but I have two ideas:
    Firstly, you are sure that the text isnīt part of the image? silly question but must be asked.
    Secondly, try moving your setText("") down a few lines, just before toolBar.add() method. or try use a different constructor: ImageIcon copyIcon = createImageIcon ("images/copy.gif");
    I am not sure if this will solve your problem but I canīt see where else the problem is coming from.
    Does the text still show if there is no image on the button?
    I think, therefore I am....... I think.

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