Add .png icons to choicebox

I have a list of observable

public static final String LIN = "Line";
    public static final String VERTICAL = "Vertical";
    public static final String HORIZONTAL = "Horizontal";
    public static final String ARROW = "Arrow";
    public static final String CHANNEL = "Channel";
    public static final String FREEHAND = "Freehand";    
    public static final String RECTANGLE = "Rectangle";
    public static final String ELLIPSE = "Ellipse";
    public static final String DOT = "Dot";
    public static final String TEXT = "Text";

    public static final ObservableList<Object> DRAW_TOOLS = FXCollections.observableArrayList(LIN, VERTICAL, HORIZONTAL, ARROW, CHANNEL,
            FREEHAND, new Separator(), RECTANGLE, ELLIPSE, DOT, new Separator(), TEXT);

and a choicebox

choiceboxDrawList.setItems(ChartConstants.DRAW_TOOLS);

http://S28.postimg.org/5nx5t2m3x/ZA147.PNG

I would like to add icons to each element of choicebox: icons are in a local folder

C:/Java/icons

and has the same name as an element in ObservableList (line.png, vertical.png, etc.).

How to get there? Examples have really enjoyed.

Thank you

Use a ComboBox instead of a ChoiceBox and plant cells.

Something like

//

ComboBox comboBoxDrawList ;
// ...
final Map icons = ChartConstants.DRAW_TOOLS.stream()
       .collect(Collectors.toMap(Function.identity(), this::createImageForDrawTool));
comboBoxDrawList.setItems(ChartConstants.DRAW_TOOLS);
comboBoxDrawList.setCellFactory(listView -> new ListCell() {
    @Override
    public void updateItem(String s, boolean empty) {
        if (empty) {
            setText(null);
            setGraphic(null);
       } else {
            setText(s);
            setGraphic(icons.get(s));
       }
   }
});

// ...
private ImageView createImageForDrawTool(String drawTool) {
   String file = ... ; // filename relative to classpath, depends on drawTool
   return new ImageView(getClass().getResource(file));
}

//

Of course, you can create a class (or same enum) to DrawTool, encapsulating the name and the image if you wish.

Tags: Java

Similar Questions

  • Have a problem to add file icon

    Hello
    I have a problem to add file icon to my desktop applications.
    I add the box not incorporated, checked...
    but I still have the problem
    Can someone tell me in detail how to solve this problem and exactly the place to put the .png file...

    Thanks in advance...

    Hello
    Thanks for the immediate response...
    I could solve the problem... in fact I just edit the .xml file in the bin-debug folder when I release build it has been verified the .xml file in the src folder and throwing the error.

  • How can I add an icon to a Web page in my bookmarks bar?

    Most Web pages have the coding for the small square icon in the bookmarks toolbar.
    Some do not.
    How can I add an icon to a Web page that does not have an assigned icon?

    It saves space for icons rather than a description of the page.

    These icons are called the favicons. Unfortunately, there no Firefox builtin feature to customize or change the favicon as the favicon is determined by a line in the HTML code of the site.

    There are many addons for Firefox that improve your browsing experience and allow you to make some customizations to Firefox. You can browse the addons of Firefox here.

    The only addon that I could find was the Favicon Images bookmarks addon, but it seems that there are some restrictions and you are only allowed to choose an icon from the list of the addon, not a custom image.

  • View all bookmarks - add an icon to the bar of the addon

    Hello

    I would add an icon to the bar of the add-on for causes the bookmark manager to the pop-up window. Even when I do the following 3 steps
    1 go to the menu bar using trackpad
    2. Select bookmarks
    3. Select bookmark all bookmarks/Show (cmd, SHIFT + B)

    I never remember to access keys and I prefer to do 1 market rather than to the present 3 steps

    I searched Add-ons and nothing came. I looked under Customize and there were 3 icons, so I tested these by dragging the bar to the add-on. None of these standard icons, triggered the Bookmarks Manager.

    Is this possible?

    Thank you

    Hi, the toolbar buttons add-on is very comprehensive and has a Bookmark Manager button. Hope that will do what you want.

    If your question is resolved by this or another answer, please take a minute to let us know. Thank you.

  • How to add an icon to the application created by the user to the e-mail toolbar

    I have a new Mac Mini, Mac Mail and El Capitan 10.11.4. I would like to add an icon to the mail toolbar to trigger an application I wrote. I tried the steps for "Finder" and who works for "Finder", but I want it on the toolbar "Mail". Can it be done? If so, how?

    BTW, I'm a professional programmer.

    I requisted you post be moved here:

    Developer forums

  • Is it possible to add an icon to a control of the enum?

    Hi all.

    I know that it is possible to customize controls, for example, you can add an icon (stickers) to a button:

    http://www.NI.com/Tutorial/14131/en/

    Is it possible to add an icon/decal to a control of the enum?

    Or do I me XControls for this?

    Thank you

    BR

    EWiebe

    Hi Wiebe,

    What about pictrings?

  • How can I add the icons on the desktop web-based

    original title: How can I add icons on the desktop as internet, g mail, shortcuts ect so I see nothing on the upper Office except listn on youtube

    How to add desktop icons

    Hello

    You don't say what operating system you are using, but it's basically the same procedure:

    Click Start > programs > find the program in the list you want to make a desktop shortcut icon > right click on the name of the program he > then move your mouse cursor on ' send to ' > then select desktop (create shortcut), or words like that.

    See you soon.

    PS You can also do the same thing with the programs listed on the left side of the start menu.

  • How do I?-A - add an icon on the desktop of my computer?

    How can I add an icon?

    http://www.Petri.co.il/add_desktop_icons_in_windows_vista.htm

    http://www.ehow.com/how_2073282_add-icon-Windows-desktop.html

    For additional information on the above:

    It's updated operating system Vista, upgraded installation and activate Forum.

    http://social.answers.Microsoft.com/forums/en-us/vistaprograms/threads

    They will help you with your question in Forum Vista programs at the above address.

    See you soon.

    Mick Murphy - Microsoft partner

  • How to add an icon on the homepage of BB

    Hello

    I want to add an icon on the home page (similar to the missed call icon) to see whether or not my application is running in the background.

    Any suggestion on how to achieve this.

    TIA

    Shiv

    see the ApplicationIndicator class. available since 4.6

  • How can I add the icon of the command prompt? I accidentally deleted.

    Original title: command prompt

    How can I add the icon command prompt, I accidentally deleted

    The location of the command line is C:\Windows\cmd.exe

    You can create a new shortcut with this path
  • Is it possible to add images/icons for a drop-down list box?

    I have created a form with several fields of text. The customer wants to be able to 'mark' some/all the of them with an icon (until there are only two icons of your choice)

    Due to the limit "real estate" on the form, it would help a lot if I could add these icons to a simple drop-down list. Unfortunately, I found no way to do it.

    Such an option exist?

    ... and if so, how?

    Thanks for any help or information

    No, but you can use a button to display images/graphics. If you are using JavaScript (for example, app.popUpMenuEx) to view the selections of text after you click the button, the script will mark the button icon to the corresponding selection. There are other similar types of things that would make with the buttons, but all rely on JavaScript. Note that this type of approach does not work on most mobile PDF viewers and not Adobe PDF viewers.

  • How to add an icon 'apple' ipad and iphone site is currently hosted on businesscatalyst?

    How to add an icon 'apple' ipad and iphone site is currently hosted on businesscatalyst?

    I'm not entirely clear what you're asking. Looks like you want to add a favorite to your devices, which is done simply by adding a bookmark on the device itself. This has nothing to do with the Muse or BC.

    Mylenium

  • Add image icon on the horizontal axis of the graph

    Hello

    Is it possible to add an icon image to horizontal axis of a graph in addition to the label?

    Guidance in this regard is greatly appreciated.

    Thank you

    Hi Fulgence,

    You can try this code... Hoping than that, this is what you need



    http://www.Adobe.com/2006/mxml">


           

    Import mx.collections.ArrayCollection;

    [Bindable]
    private var expensesAC:ArrayCollection = new ArrayCollection ([] collection
    {Month: "Jan", profit: 2000, expenses: 1500, amount: 450},
    {Month: benefit "Feb": 1000, expenses: 200, amount: 600},
    {Month: "Mar", profit: 1500, expenses: 500, amount: 300},
    {Month: "ARP", profit: 1800, expenses: 1200, amount: 900},
    ([{Month: "May", profit: 2400, expenses: 575, quantity: 500}]) ;
    ]]>
       


       
       
       


       
       
       


    Height = "100%" width = "100%" layout = "horizontal" >


    paddingLeft = "5" = "5" paddingRight
    showDataTips = "true" dataProvider = "{expensesAC}" >
                   
               
                   
               


                   
                   
                   
               

           


    paddingLeft = "5" = "5" paddingRight
    showDataTips = "true" dataProvider = "{expensesAC}" >
                    
               
                   
               

      
       
        
         
          
           
                         
    override public function set data(value:Object):void
    {
    If (value! = null)
    {
    axisLabel.text = value.text;
    }
    }
    ]]>
              


           
          
         
        
       
      
               
                   

                   
                   
               
           
               
           


    Thank you

    Jean Claude Chari

  • How can I add PNG image using custom?

    Hi guys,.

    It's my custom component.

    <components:EmployeeDisplay imageFile="abrilliam.png"/>


    Can you help me please how to add png format image.
    when i add png format image that time this image not displayed.
    what can i do?


    Thanks
    JaxNa

    Hi Jaxna,

    In your code below custom component, I could see no imageFile variable declared...


    http://ns.Adobe.com/MXML/2009.
    xmlns:s = "library://ns.adobe.com/flex/spark".
    xmlns:MX = "library://ns.adobe.com/flex/mx" >
          
       
    source = "images / {imageFile}" / > "
        
       

    Have you declared the imageFile variable in your component file above... check it out?

    If it is then declared to declare a variable of datatype Sttring imageFile and make Bindable...

    [Bindable] private var imageFile:String ="";

    Your new component code must therefore:


    http://ns.Adobe.com/MXML/2009.
    xmlns:s = "library://ns.adobe.com/flex/spark".
    xmlns:MX = "library://ns.adobe.com/flex/mx" >

    [Bindable] private var imageFile:String ="";


    source = "images / {imageFile}" / > "
        
       

    Also check the path to the image once... If it is given the correct path of the hierarchy...

    Thank you

    Jean Claude Chari

  • an add on icon called 'supported site' contains the history of the site supported and cannot be removed or deleted. That's what I want to do, but cannot do so

    In the same menu adjacent to the star favorite is an icon that opens with the name 'Sites supported' and he holdds the history of visited sites (this is not the historical record). I have the site set up for not remembering history.
    Down to brass tacks. all I want to do is permantly get rid of this icon (supported sites) and its history.
    I started Firefox in safe mode, and the icon will not appear. But as soon as I re - open firefox, yes you guessed the bloody icon and all its content is still their.

    Type of topic: addons< enter > in the address bar to open your add-ons Manager.
    Access key; < Control >(Mac = < Command >)< shift > has)

    In the Manager of Add-ons, on the left, select Extensions.
    Find the module, then select delete.

    However, if there is no button Delete, then it is a plugin.
    You need to remove the main program from your system.

Maybe you are looking for

  • Help! Malfunction of MacBook retina SD card slot

    Hello Recently, I wanted to use my card slot for a Micro SD card on my macbook 2012 end retina pro website. After inserting the card, I gives me the message "the disk you inserted is not readable by this computer. I then followed the button «Initiali

  • had to install the new operating system and bookmarks are gone

    Hiya. I had problems with the computer and the fix was to install a new operating system (windows 7 it was old, windows 8 is the new). Most of my old files make the switch, but when I downloaded firefox, my favorites have disappeared. I looked in my

  • MozBackup file was about 16 000 Ko. It is now 764 000 KB. Why?

    MozBackup takes a lot of time now to add the Adblockplus ini files, increase in the size of backup. How to stop Mozbackup FIXED whitelisted files?

  • Firefox is locked up on me. Is there a way to fix this.

    It does more and takes about 30 seconds to get out. I searched and found 'suspended', but nothing there seems to be a problem that I can tell. He started a week ago and is getting worse all the time. It happens especially when I click on a bookmark i

  • I can't open Firefox on my Satellite Pro A300

    Satellite Pro A300 - Windows XP - I downloaded Firefox, but when I click to open it I get the icon of the hourglass for a while but eventualy it disappears and nothing happens. I use IExplorer without any problem, but I want to use Firefox as my pref