Own definition of Icon for JMenuItem

Every time I try to add ColorIcon to JMenuItem it eats name space. How can I separate name from icon?
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Toolkit;
import javax.swing.AbstractAction;
import javax.swing.Icon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
public class Test extends JFrame {
     public Test() {
          JMenuBar menu = new JMenuBar();
          JMenu mFile = new JMenu("File");
          menu.add(mFile);
          JMenu mColor = new JMenu("Color");
          mFile.add(mColor);
          mColor.add(new TakeAction(Color.RED, "This is red"));
          setJMenuBar(menu);
          Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
          setPreferredSize(new Dimension(screenSize.width/2, screenSize.height/2));
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          pack();
          setLocationRelativeTo(null);
          setVisible(true);
     public static void main(String[] args) {
          new Test();
     public class TakeAction extends AbstractAction implements ActionListener{
          public TakeAction (Color color, String name) {
               super(name);
               putValue(SMALL_ICON, new ColorIcon(color));
          @Override
          public void actionPerformed(ActionEvent e) {
     public class ColorIcon implements Icon {
         private int width = 15;
         private int height = 15;
         private Color color;
         public ColorIcon(Color color) {
              this.color = color;
          @Override
          public int getIconHeight() {
               return 0;
          @Override
          public int getIconWidth() {
               return 0;
          @Override
          public void paintIcon(Component c, Graphics g, int x, int y) {
               Graphics2D g2d = (Graphics2D) g.create();
                  g2d.setColor(color);
                  g2d.fillOval(3, 3, width-3, height-3);
                      g2d.dispose();
}Edited by: Giraphant on Dec 30, 2010 3:23 AM
Edited by: Giraphant on Dec 30, 2010 3:24 AM

private int width = 15;
private int height = 15;
@Override
public int getIconHeight() {
  return 0;
@Override
public int getIconWidth() {
  return 0;
}Does this make sense to you?

Similar Messages

  • Here's how to use your own custom Webclip icons for the sites you visit.

    This method is pretty much 95% taken from this URL: http://allinthehead.com/retro/319/how-to-set-an-apple-touch-icon-for-any-site , so credit where credit is due. The instructions are a bit hard to understand though, so I'll try to make it easier for everyone.
    Fortunately, this works for both Macs and PCs.
    INSTRUCTIONS:
    Requirements:
    - iPhone on 1.1.3 and any version of iTunes that can sync to iPhone
    - Adobe Photoshop or any other image editing program that can crop, alter image size, and save .png image files. (Recommended 24-bit .pngs as they are higher quality)
    - Apple Safari ( http://www.apple.com/safari/, and yes, you need it.)
    - A website or ftp where you can upload images and directly link to them, like Google Pages.
    Warning:
    - This requires you to sync your Safari bookmarks to your iPhone. You will probably lose all of your iPhone's bookmarks if you don't already sync your Safari bookmarks with your iPhone. Only proceed if you do not mind losing your iPhone's current bookmarks and do not mind re-entering them after the bookmark sync. NOTE: The bookmark sync DOES NOT get rid of your current Webclips though, so don't worry about those.
    Easy Steps:
    1) First, make sure that you are following these instructions in the Apple Safari web browser.
    2) Find an image you wish to make into a Webclip icon. (ex: I prefer to use movies.yahoo.com to look at movie showtimes, so I found an image of a movie reel from Google Image Search and decided to use that.)
    3) Open the image with your preferred image editor and crop your desired image into a perfect square. Resize that picture down to 57x57 pixels. Save as a 24-bit .png file. Upload the icon to your webpage or ftp. (ex: I ended up with this icon of a movie reel: http://ctolpin.googlepages.com/appleicon01.png )
    4) Select and copy the javascript code in this .txt file: http://ctolpin.googlepages.com/webclipcode.txt
    5) Go to Bookmarks and select "Add Bookmark..."
    6) Type in "Webclip Icon URL"
    7) Go to Bookmarks again and select "Show all Bookmarks."
    8) Right-click your new "Webclip Icon URL" bookmark and select "Edit Address"
    9) Paste your clipboard's contents into the field.
    10) Plug your iPhone into the computer if it's not connected already.
    11) In iTunes, select your iPhone from the right column. Select the Info tab. Scroll down to "Web Browser" and check "Sync bookmarks with: Safari" (obviously, make sure Safari is selected from the dropdown menu).
    12) Once your iPhone is synced, use your iPhone to navigate to your intended website target to make into a Webclip. Remember that Webclips save where you zoom in as well! (ex: For me, it was movies.yahoo.com and then entering in my zip code.)
    13) Once you've loaded your target website, open up the bookmarks in iPhone's Safari, select Bookmarks Bar, then select Webclip Icon URL.
    14) Type in the address of your uploaded icon. (ex: In my case, it is http://ctolpin.googlepages.com/appleicon01.png)
    15) iPhone's Safari will seem like it didn't do anything. However, add that webpage now to your home screen as a Webclip. Magic.
    Additional note:
    It is easiest to make a bunch of icons at first and to upload them. However, once that "Webclip Icon URL" bookmark is in your iPhone, there is no need to go back and do any of the computer Safari steps again
    My front page icons in order (Sorry Stocks, it's the second page for you!):
    Google, Wikipedia, Definr, Showtimes
    http://ctolpin.googlepages.com/iphonecampics007.jpg
    Message was edited by: LumpOfCole

     3 Go to the port forwarding section and copy down the Applied Rules. 
    Example:  
    Network Computer/Device: 192.168.1.100:63145
    Application & Ports Forward:  Application UDP Any -> 6347  
    Note: There may be up to three entries for each one of your Set Top Boxes.G
    Your display obviously is not like mine as mine does not dosplay the port associated with the ip address
    whatever, the STB's start at 192.168.1.100 and icement by 1 for each
    the port addr's will be 63145 alo incrementing by 1
    there is 1 entry for each in my pf list
    however each ip addr also has a port entry starting at 35000 also incrementing by 1 for each ip addr
    For some unknow reason these are duplicated e.g I appear to have 11 entries exaactly the same for each stb and as the fios services rules have no action switc there is nowhere to delete the extraneous garbage.
    Why do you clone the mac addr??

  • Can i design my own social media widgets  for Facebook, etc

    I would like to design my own social media icon for my widgets (Facebook, pinterest, etc) Is that possible?

    Hi,
    not exactly in Adobe Muse, but you can create an icon using Photoshop easily, I found a tutorial for you,
    http://tutvid.com/photoshop/create-facebook-twitter-buttons-photoshop-tutorial/
    If you meant something else or I f I missed anything, please let me know.

  • My Firefox home page displays a weather icon for New York , how can I change it for my own location? It only shows for USA

    At the bottom of the screen there are several icons for weather forcasts ect. for New York. How can I channge these icons to show the forecast for my own location? When I try to change location all I can get are locations for the USA

    What web page do you have set as your homepage?

  • Setting icon for the JMenuItem

    I am trying to set the Icon for the JMenuItem and not able to do so.
    I have the Images directory in the classes which has all the images. Is this the way to give the dir path. When do I give '\' and when do I give '/' or'//' or'\\'? Thanks.
    I gave
    JMenuItem mnuitmFileNew = new JMenuItem(new ImageIcon("Images//new.jpg"));
    and later in Jbinit() method I have this.
    mnuitmFileNew.setMnemonic('N');
    mnuitmFileNew.setText("New");
    mnuitmFileNew.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    mnuitmFileNew_actionPerformed(e);
    });

    Hi,
    I'm not sure if you've seen this yet:
    http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html
    If you still have any questions please post again.
    Regards,
    Matt
    Java Developer Technical Support
    Sun Microsystems

  • How to set my own icon for java frame ??

    I create a java class it extends JFrame. I want to change default icon on the left_top corner and using my own icon. It is a --.gif file. How to do it. When I try to modify it using setIconImage( Image image), I met problem. I cann't new Image("--.gif"). I don't know how to create a Image object using a string(file name). I try to use ImageIcon , but it is not image obj. Thanks. Gary

    According to the documentation setIconImage does the following: Sets the image to be displayed in the minimized icon for this frame. Not all platforms support the concept of minimizing a window.
    So,
    1) It does not change the icon in the top-left corner
    2) It does not work on all platforms.

  • Animated gif icon for an exception instead of the standard icon?

    Hello,
    is there a possibillity to use an animated gif icon for an exception instead of the red standard icon in a web template?
    I tried  to change the standard icon s_s_ledr.gif against an animated gif icon in the mime repository, but it does not work. In the IE the icon is still shown without animation.
    Maybe I´ve changed the wrong icon?
    Can you please help me?
    Greetings
    Andreas
    Edited by: Andreas Zenner on Feb 25, 2009 1:22 PM

    Hi Andreas,
    it is possible to integrate own symbols for exceptions. If you can use animated gif I don't know. However there is a post over here explaining the usage of the modification for symbols:
    Re: BI 7 Web Design API - Parameter modification - Exception symbol
    If you have questions just let us know.
    Brgds,
    Marcel

  • Custom home screen icon for a webapp.. just like Google - How?

    I noticed that when you add Google to your home screen it displays a custom icon.. not an image of the website like other sites. I am trying to figure out if there is a way to do this for my own webapps. I searched through the Google.com source code but didn't find anything that appeared to have anything to do with that icon.
    Hopefully this is possible for developers. Right now most of my icons are all white and its hard to distinguish which is which without reading the text below it.

    Found it on the iPhone web dev page..
    iPhone and iPod touch allow a user to save a WebClip bookmark to your site on their Home Screen.
    To specify a bookmark icon for all pages of a web site, place a PNG image named "apple-touch-icon.png" at the root directory of your web server - similar to the "favicon.ico" for site icons.
    To override the site bookmark icon on a specific web page, insert a <link> element similar to <link rel="apple-touch-icon" href="/customIcon.png"/> within the <head> element of the page.
    The bookmark icon dimensions should be 57x57 pixels. If the icon is a different size it will be scaled and cropped to fit.
    Safari will automatically composite the icon with the standard "glassy" overlay so it looks like a built-in iPhone or iPod application.

  • How to change the icon for print dialog?

    Hello,
    I have a JTable, and with the print() method, I'm able to bring up the Print dialog and successfully print the contents of the table. Example:
    myTable.print( JTable.PrintMode.FIT_WIDTH, myHeaderFormat, myFooterFormat );This works great, but one small detail I'd like to change is the icon in the top-left corner of the dialog. The icon is currently the default Java coffee cup icon, while the rest of my application uses my custom icon. I couldn't find any documentation in the API or tutorials that Java has listed which shows how to change the icon, so I'm not even sure if it's possible (but why shouldn't it be?).
    My question is this: Is it possible to change the default icon in the print dialog? Or do I have to either make my own print dialog somehow, or use a third-party print dialog?
    Thanks

    tjacobs01: Appreciate the assistance (despite your sass). I've already searched the API, tutorials, and this forum. I'm already well aware of the setIconImage() method for JFrame -- after all, that's how I set the icon for my other frames as I previously mentioned. However, I want to set the icon for the print dialog called from the print() method of JTable.
    How would I use setIconImage() for the print() method of JTable? The print() method returns a boolean value, not a JFrame, so I'm just not sure how to implement what you're saying.
    Thanks

  • How to change the icon for 'windows group' in Java 1.6 [Windows XP] ?

    Hello,
    I was wondering if there is a possibility to change the icon for 'windows group' in Java 1.6...
    I'm using Windows XP SP2. Now the windows from my Java 1.6 application are grouped with the standard Sun icon [screen below] on the group.
    http://img382.imageshack.us/img382/8995/iconbl1.png
    I would like to change the icon for my own. Is there a way to do that ?
    Please help.

    Whichever icon I use for the main frame (I tried few), after grouping the main frame and other sub-frames the icon is changed to standard 'Java Sun' icon as you can see in the screenshot from my first post. The problem occurs only when frames are grouped, when the are separated in the task bar their titles and icons are ok...
    So how can I change the icon/title for the group only (for Java 1.6 in Windows XP) ?

  • How do i make an icon for a new genre

    I'd like to create a new genre in iTunes for my collection,  and would like to create an "icon" similiar to the ones that are plugged into iTunes already.  I know if there isn't one it will default to an album cover.  Is there a way of doing this?  I want to make a genre for 'meditation', which I know how to do...I just want it to display like the other genres.
    Thanks in advance,
    GuiseppeNW

    iTunes comes with a limited number of pre-defined genre images aka badges. Some of these images are associated with more than one genre, e.g. Alternative is connected to Alternative, Alternative & Punk, Alternative Country, Alternative Folk, Alternative Metal, Alternative Pop/Rock, Alternative Punk, Alternative Rock, AlternRock, Punk, Punk Rock, Punk/Folk, Punk/Folk/Reggae and no doubt many others that aren't represented in my library. The dance image is linked to Dance, House, Techno & Trance or genres begining with those words.
    If there is no default icon for a particular genre then itunes will display a cover from one of the albums with that genre. If you run your mouse pointer slowly across the image from one side to the other it will change to display the covers of each of the albums in that genre in turn. You can right/option click on any of these to Set Default Grid Artwork and that image will then be used to represent that genre. Use Clear Default Grid Artwork to reset things.
    If you want to add your own custom genre badges, using artwork that is not in your albums, then place the images you want to use in the folder C:\Program Files\itunes\iTunes.Resources and edit the file C:\Program Files\iTunes\iTunes.Resources\Genres.plist using something like Notepad++ to connect the required genres to your new images.
    tt2

  • Can you have a pdf as an icon for single click access on ipad or iphone?

    can you have a pdf as an icon for single click access on ipad or iphone?

    No - I think Safari is the only app that can have separate shortcuts (for different sites) on the homescreens. You can only access PDFs by first going into it's owning app.

  • How to create shortcut icons for settings

    how to create shortcut icons for settings

    I also have this issue. Apple has indicated they want to have a larger presence in businesses. VPN is a huge part of any business network. Frustrations are hightened by the VPN disconnecting whenever the device Auto-locks. We have a definite need to make VPN's on iPads less tedious...

  • Custom icon for JOptionPane.showInputDialog

    As a novice who's wading through Deitel's 'Java how to program', using java2 and j2sdk1.4.1 on JCreator Pro. I want to use my own icons on a small proggie i've written. I know that the format is:
    showInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue)
    however this doesn't tell me how to write the code. how do i change the default '?' icon for my own icon?
    thanks for any help
    rgds
    adambi

    This should help you also
                ImageIcon ico = new ImageIcon("drag2.jpeg");
                Frame frame = new Frame();
                Object[] options = {"Yes, please",
                        "No, thanks",
                        "No eggs, no ham!"};
              JOptionPane.showInputDialog(frame,
              "What some eggs ?.",
              "My title",JOptionPane.ERROR_MESSAGE,ico,options,
        options[2]);also here is a good link for ya on dialogs
    http://java.sun.com/j2se/1.4/docs/api/
    GOOD LUCK

  • Icon for a Custom Component

    Hi --
    I am building a custom component and I have tried to create
    the icon for the
    component using
    [IconFile("iconMaskInput.png")]
    but its not working. Can someone help me out?
    Rich

    Hi --
    I followed your instructions and updated the icon for the
    movie clip inside
    my FLA file that I compiled into a SWC file. However, when I
    installed the
    SWC file the icon did not update in the palette. Is this
    because I had
    already installed the component once? Or did I do something
    wrong?
    Thanks
    Rich
    "gnfontaine" <[email protected]> wrote in
    message
    news:fm4dqs$or1$[email protected]..
    > You need to add it to the component inspector first,
    then copy it into the
    > same
    > folder where you create the install package.
    >
    > 1.) Under the component definition found in the library,
    click the default
    > icon You will be present with a list, the last choice is
    custom.
    > 2.)Check the box display in components panel.
    > 3.)If you are going to distribute the component using
    mxp package, make
    > sure a
    > copy of the component is in the same folder as the mxi
    file and that you
    > add it
    > to the files node in the mxi definition.
    >
    > Hope this helps
    >

Maybe you are looking for

  • New development: Safari crashes now

    In the past couple of days and without having made any changes to my Macbook Pro's system settings, Safari 6.0.4 crashes every time I try to do something once it's opened. I cannot reload a page, add a comment, move from one page to another, or anyth

  • Indesign keeps crashing on instalation of trial creative cloud

    I have downloaded the trial vertion of  creative cloud fine but when i try to try indesign cs6 the download compleats but when it is installed about 50 % it keeps crashing and freezing my comp... Am i doing somthing wrong.?

  • Landscape mode

    Recently when playing music on my ipod 5, it gets stuck in landscape mode and I am unable to access my playlists or music controls. Cannot get it out of landscape mode, even exiting music and then going back doesnt fix this. Is there a way to get it

  • JavaME SDK 3.0 EA Mac OSX: Preverify error :(

    Hi, Since my Windows box died on me recently I was extremely happy to learn that the JavaME SDK for Mac is in EA and downloaded and installed the whole thing. All went fine until I tried to compile my project and got preverification errors that don't

  • How can I use Measuremen​t Studio components in SharpDevel​op?

    I tried to use NationalInstruments.UI.WindowsForms.Led in sharpdevelop (http://www.icsharpcode.net) and I got a message about the product not being licensed for use with this program. Is it possible to attain licensing for use with sharpdevelop or is