Set Icon for toggle button

I created Icon with Borderpane, image and text which I want to set as button icon.
@Override
    public void start(Stage primaryStage)
        final VBox vbox = new VBox();
        // create 3 toggle buttons and a toogle group for them
        ToggleButton tb1 = new ToggleButton();
        tb1.setGraphic(newConnectionIcon());
        ToggleButton tb2 = new ToggleButton();
        ToggleButton tb3 = new ToggleButton();
        final ToggleGroup group = new ToggleGroup();
        tb1.setToggleGroup(group);
        tb2.setToggleGroup(group);
        tb3.setToggleGroup(group);
        // select the first button to start with
        group.selectToggle(tb1);
        final Rectangle rect1 = new Rectangle(300, 300);
        rect1.setFill(Color.DARKOLIVEGREEN);
        final Rectangle rect2 = new Rectangle(300, 300);
        rect2.setFill(Color.LAVENDER);
        final Rectangle rect3 = new Rectangle(300, 300);
        rect3.setFill(Color.LIGHTSLATEGREY);
        tb1.setUserData(rect1);
        tb2.setUserData(rect2);
        tb3.setUserData(rect3);
        group.selectedToggleProperty().addListener(new ChangeListener<Toggle>()
            @Override
            public void changed(ObservableValue<? extends Toggle> ov, Toggle toggle, Toggle new_toggle)
                if (new_toggle == null)
                else
                    vbox.getChildren().set(1, (Node) group.getSelectedToggle().getUserData());
        HBox hBox = new HBox();
        hBox.getChildren().addAll(tb1, tb2, tb3);
        hBox.setPadding(new Insets(10, 10, 10, 10));
        vbox.getChildren().addAll(hBox, (Node) group.getSelectedToggle().getUserData());
        StackPane root = new StackPane();
        root.getChildren().add(vbox);
        Scene scene = new Scene(root, 800, 850);
        primaryStage.setScene(scene);
        primaryStage.show();
    private static BorderPane newConnectionIcon() {
        // Add background effect
        DropShadow ds = new DropShadow();
        ds.setOffsetY(2.0);
        ds.setOffsetX(2.0);
        ds.setColor(Color.GRAY);
        // New BorderPane which will hold the components
        bpi = new BorderPane();
        bpi.setEffect(ds);  // Add the effect
        bpi.setCache(true);
        // Set the size of the BorderPane
        bpi.setPrefSize(30, 30);
        bpi.setMaxSize(30, 30);
        // Add style       
        bpi.setStyle("-fx-background-color: linear-gradient(#f2f2f2, #d4d4d4);"
                + "  -fx-background-insets: 0 0 -1 0, 0, 1, 2;"
                + "  -fx-background-radius: 3px, 3px, 2px, 1px;");
        // Add Label to the Icon
        Text inftx = new Text("New Connection");
        inftx.setFont(Font.font ("Verdana", 5));   // Set font and font size
        inftx.setFill(Color.WHITE); // Set font color
        ncpic.setFitHeight(25);    // Set size of the Icon picture
        ncpic.setFitWidth(25);
        // Internal StackPane which will hold the picture and the Icon Label
        StackPane stack = new StackPane();
        stack.getChildren().addAll(ncpic, inftx);   // Add the picture and the Label
        // Add the StackPane to the main BorderPane       
        bpi.setCenter(stack);
        // Change the border of the Icon when the mouse is over the Icon
        bpi = mouseOver(bpi);
        // Navigate to new Panel when the user clicks on the Icon
        bpi.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent t) {
        return bpi;
How I can remove the default togglebutton and use the my custom icon as a button?

Yes, they are icons and they are called "handles". The easiest way to change then is to use UIManager.
If you haven't done so before, look through the hash table UIManager.getLookAndFeelDefaults().
import java.awt.*;
import java.net.*;
import javax.swing.*;
public class TreeIcons {
     public static void main(String[] args) throws MalformedURLException {
          String prefix = "http://forum.java.sun.com/images/";
          UIManager.put("Tree.openIcon", new ImageIcon(new URL(prefix + "dont_save.gif")));
          UIManager.put("Tree.closedIcon", new ImageIcon(new URL(prefix + "save.gif")));
          UIManager.put("Tree.leafIcon", new ImageIcon(new URL(prefix + "forum_new.gif")));
          UIManager.put("Tree.expandedIcon", new ImageIcon(new URL(prefix + "email_faded.gif")));
          UIManager.put("Tree.collapsedIcon", new ImageIcon(new URL(prefix + "email.gif")));
          JFrame f = new JFrame("TreeIcons");
          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          f.getContentPane().add(new JTree());
          f.setSize(new Dimension(300,400));
          f.setLocationRelativeTo(null);
          f.setVisible(true);
}

Similar Messages

  • Set icon for toggle control of JTree node.

    hi.
    Just a question.
    I am looking towards setting the icons of the JTree by this i mean the icon that you click on
    to open say a node .
    I know you can set the icons of the nodes by setIcon inside your TreeCellRenderer but i doubt that
    that will set the icon that is to the left ot your label.
    Has anyone gone down this path recently.
    The class BasicTreeUI has a method
    called paintExpandControl( Graphics g,
    Rectangle clipBounds,
    . Insets insets,
    Rectangle bounds,
    TreePath path,
    int row,boolean isExpanded,
    boolean hasBeenExpanded,
    boolean isLeaf)
    Hopefull this is a method that can paint the toggle node so has anyone subclassed BasicTreeUI and done something like this recently.
    Any advise on the topic is really appreciated.
    Thank you.

    Yes, they are icons and they are called "handles". The easiest way to change then is to use UIManager.
    If you haven't done so before, look through the hash table UIManager.getLookAndFeelDefaults().
    import java.awt.*;
    import java.net.*;
    import javax.swing.*;
    public class TreeIcons {
         public static void main(String[] args) throws MalformedURLException {
              String prefix = "http://forum.java.sun.com/images/";
              UIManager.put("Tree.openIcon", new ImageIcon(new URL(prefix + "dont_save.gif")));
              UIManager.put("Tree.closedIcon", new ImageIcon(new URL(prefix + "save.gif")));
              UIManager.put("Tree.leafIcon", new ImageIcon(new URL(prefix + "forum_new.gif")));
              UIManager.put("Tree.expandedIcon", new ImageIcon(new URL(prefix + "email_faded.gif")));
              UIManager.put("Tree.collapsedIcon", new ImageIcon(new URL(prefix + "email.gif")));
              JFrame f = new JFrame("TreeIcons");
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              f.getContentPane().add(new JTree());
              f.setSize(new Dimension(300,400));
              f.setLocationRelativeTo(null);
              f.setVisible(true);
    }

  • Setting icon for buttons in labview 6i

    Hi All,
    Currently i am working on Labview 6i. i created two buttons in my vi one button is used to perform the test, another will be used to exit from the test. i would like to add icons for those buttons. can anyone tell me how to add icons for buttons.
    Thanks,
    kalpana

    You realize that LabVIEW 6.0 is at least 15 years old? That would be almost equivalent to working with a Windows 98 machine nowadays!
    Yes your picture can't be imported in LabVIEW 6.0 on my machine either. I haven't checked about all the details, but the LabVIEW import in 6.0 doesn't seem to work for png and gif images but only for bmp. Newer versions do work for your png file including honoring the transparency at least since version 7.1.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • ICON for a Button( Forms 4.5)

    I am trying to show an ICON for a Button
    in Forms 4.5 under Windows OS.
    I am not able to find any of these
    TK_ICON, UI_ICON and TK25_ICON in the registry
    to set the path.
    Shoud I have to install any other utility/option ?
    please guide me

    Just create the new registry entries by yourself under
    H_KEY_LOCAL_MACHINE/SOFTWARE/ORACLE and write the correct path
    inot it.
    Michael

  • How to set value for radio button in sap crm survey suite

    Hi ,
    I created a survey in CRM Service, in which I added a question with answer as '10 Selection Button Group ('radio button'). And answer has 11 answer options (which means 11 radio buttions). Now when we test the survey, the value for the radio buttons is appearing like 'id_0050569b03091ee480a29d8ee61e953c'. But i want to set a specific value for each radion button (from 1 to 11). So, how to set value for radio button in sap crm survey suite???.
    Thanks & Regards,
    Seshu

    Hi,
    I found solution myself. Click on Goto -> Editing Mode -> Expert Mode. Now you can set value for radio button.
    Regards,
    Seshu

  • Programmatically setting value of toggle button?

    Is this not possible? I've looked at the help for both SetCtrlVal() and SetCtrlAttribute(), and it doesn't look like it can be done. True?
    My app has a control button to clear the displayed graph. It would be nice if the function's first action were to set the value of a toggle button to "OFF." Any other way of accomplishing this?
    Thanks.
    Solved!
    Go to Solution.

    Well, then I must be forming the call incorrectly. I couldn't find an example using ATTR_CTRL_VAL, so I wrote this:
    rc = SetCtrlVal (g_hmainPanel, PANEL_MAIN_TOGGLEBUTTON, ATTR_CTRL_VAL, 0);
     And I get the run-time error:
    NON-FATAL RUN-TIME ERROR: "cleargraph.c", line 30, col 84, thread id 0x00002EE8: Too many arguments to variable argument function.
     So, if the ATTR_CTRL_VAL form of the call doesn't accept any more arguments, how do I inform the command of the state I wish to put the control into?
    Thanks.

  • 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

  • Setting icon for MII version 12.1.x custom action

    Hi,
    i tryed to set icon image for custom action for MII version 12.1.x but i did not achieve.
    How can it be done?
    Thanks.

    Hello,
    I have done it in 11.5. This is how I did it in 11.5. (I am hoping that it has not changed in 12.1)
    //funciton for specifying icon
    public String GetIconPath() {
            return "com/path/to/icons/imagename.png";
    Store your image file in the following way
    com/path/to/icons and name that as imagename.png
    There is also a blog on it
    /people/rupesh.bajaj/blog/2007/12/04/beginners-guide-to-create-custom-action-block
    I hope it helps.
    Regards,
    Musarrat
    Edited by: Musarrat Husain on May 17, 2011 12:18 PM

  • Using search help icon for a button

    Hi Experts,
    For a Webdynpro layout I have created a button and I want to assign an icon/image similar to the search help image(two squares type).
    Is there any way to assign the webdynpro search help icon to a button?
    I was searching in ImageSource under Button property but did not find any similar image. Else Is there any option to upload and assign an image to the button?
    Thanks.

    Hi,
    Under properties of button press F4 in image source attribute, you can select standard SAP icons, if not you can upload icon to your web dynpro component and then press F4 and select Component images tab and select your icon.
    For uploading icons to web dynpro abap check this reference: [Displaying Logos in WDA|http://www.****************/Tutorials/WebDynproABAP/Logo/Page1.htm]
    Hope this helps u.,
    Thanks & Regards,
    Kiran.

  • Globally setting icon for a file type

    I've been using LilyPond a lot recently. The .ly files it saves don't have their own icon, though, they just get the generic document icon. I know that I can manually set an icon for a single file using 'Get Info', but it's not practical now because I have so many .ly files. Is there a way I can tell OS X to use my own icon every time it sees a .ly file?
    Thanks,
    (- Steve -)

    Hi, Stephen.
    If by LilyPond you mean this application, it's the application's responsibility to assign the custom icon for files it creates, e.g. .ly files you edit and save in LilyPond. You might want to send feedback concerning this to the developers. However, as I understand the application based on a quick review of its manual, it can work with any plain-text (ASCII) file.
    You can change the default application in which all .ly files open by using the instructions in "Mac OS X 10.4 Help: Changing the application that opens a document." That may result in those files bearing the same icon as the LilyPond application. That is also the mechanism by which a given icon is assigned to all files of a given type.
    Good luck!
    Dr. Smoke
    Author: Troubleshooting Mac® OS X

  • Change title, tooltip and icon for About button in published Webhelp?

    About Webhelp  is just plain wrong.  The tooltip ought to read "About <project name>" and the title bar for the About window should be eliminated (or else have it read About <project ver xx>.
    How do I do this?
    Likewise, is it possible to change the ICON for the About dialog in the toolbar of a published Webhelp project?

    I have the same issue.
    I modified the whskin_banner.htm file to control what displays for the About button.  The only thing I can't figure out is how to modify the tooltip.  It still says "About Webhelp" when you hover over it.
    I searched the whskin_banner.html file for the words "About Webhelp" but nothing was found.  I looked in the Edit Skin wizard and couldn't find anything either.  I also searched the Skinny on Skins and it doesn't address this issue.
    How do I change the About tooltip? Did I miss something?
    Thanks!

  • Icons for globals buttons

    Where can I found Icon library for global button in BLAF standard (Connection, Help, Home page, Login, Logout, Preferences, etc).

    http://otn.oracle.com/tech/blaf/specs/icon_list.html

  • [SOLVED] Set icons for applications in XFCE

    Hi,
    I was wondering if I can specify the icons for applications. Currently my gVim is using a "general" icon when in the panel but has the right icon when I create a launcher. This is how it looks like. Any suggestions?
    Thanks!
    Last edited by dsdeiz (2011-01-10 00:50:57)

    Hi,
    Yep, I have a gvim.desktop in /usr/share/applications. What it contains is:
    Type=Application
    TryExec=gvim
    Exec=gvim
    Icon=gvim
    Terminal=false
    Type=Application
    TryExec=gvim
    Exec=gvim
    Icon=gvim
    Terminal=false
    There is also gvim.png in /usr/share/pixmaps.

  • Custom icon for bar button item on iPhone?

    Hey all,
    I'm trying to set a custom image as a bar button item in my iPhone app and can't figure it out. I don't want the image inside a button, I want the image to be the button itself. If I use initWithCustomView the area isn't clickable anymore (unless I'm missing something).
    Does anyone know how to do this?
    Thanks,
    Mike O.

    I am having the exact same problem, but I cannot figure out the solution. I tried initWithCustomView: with a UIImageView, and then with a UIButton. If I set the UIBarButtonItem's target and action, that method does NOT get called in either scenario, and when i set the UIButton's target and action in the latter scenario, it STILL does not get called. Could you post your working sample code? Here is an example of my code which DOES NOT WORK!
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:@"NowPlaying.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(nowPlayingButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    nowPlaying = [[UIBarButtonItem alloc] initWithCustomView:button];
    nowPlaying.action = @selector(nowPlayingButtonClicked);
    nowPlaying.target = self;
    Thanks for your help.
    Message was edited by: Ben Sussman

  • Setting icon for the attachment

    Anyone know how to set the icon of the attachment?
    I have no problem sending attachment (in this particular case of *.xls files), but the email I received using NOTES shows a default grey box with the correct file. Tried using NOTES to send Excel attachment, and it showed up with a nice icon indicating Excel file. How can I do the same? Thanks in advance.

    I have had a similar problem and have not been able to determine whether the problem is related to Windows XP Pro, Lotus Notes 5.0.11, or Microsoft Office/OpenOffice. A search of the Internet turned up a number of related issues (attachment icon is missing/invisible, etc).
    The Java program I use to email attached files used to work without any problems, but sometime after I moved to an XP workstation, installed Open Office, and applied XP Service Pack 1, the attachment icons (at least for some file types) became invisible. I can't help suspect that the problem lies in XP or Office, but I have not been able to determine that for sure.
    FWIW: A suggested workaround (from the Lotus Notes forum) is to change your screen display from 32 colors to 16 colors. This has helped make the attachment icons visible when sending mail from Notes, but it has not helped the Java Mail attachments become any less invisible. Maybe the next step would be to go to a monochrome display?

Maybe you are looking for

  • How can I get the e-mail address (reply addr.) once connected to a server

    My application ask the user to enter the POP3 server host name (+ port) more the POP3 server userId and password .... I can get the e-mails and show the to the user .... Now, the user want to send a message from that "account" and what I need is to k

  • Funtion Module for user exits  variables in BEx Queries.

    Hi, This is for BW Query customer exit variable (zvar2) for include ZXRSRU01 and exit :EXIT_SAPLRRS0_001. Can anyone please suggest the function modules that can be used to do the following. 1)Read value of zvar1 from selection screen whatever    use

  • One or more frames were dropped during playback???

    I have finally complete my movie.... now when I play it back there are two clips which produce this error message: "One or more frames were dropped during playback" It tells me I can: "Turn off unlimited RT" (which is off) "lower compression data rat

  • JavaScript in WD

    Hi everyone, I am trying to get JavaScript running with my WD application. In the interface view, I created an Outbound plug called Exit. I added that interface view to my Main view. This is how I call the outbound plug :    wdThis.wdGetMyAppInterfac

  • How to enable HTTPS Port in abap system

    Hello All, Hope all are doing great,can any one please tell me the procedure step by step how can i enable https port in my only abap system,is it required to enable ssl also for this?.. Regards, Syed