How to resize the Icon such as 1.gif, 2.gif, 3.gif etc at my will??

Dear friends:
I have following code to add the Icon to the nodes of the JTree,
But I hope to resize the Icon such as 1.gif, 2.gif, 3.gif etc at my will, not fixed one, How can I do it??
Thanks
Sunny
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
/** JTree with missing or custom icons at the tree nodes.
*  1999 Marty Hall, http://www.apl.jhu.edu/~hall/java/
public class CustomIcons extends JFrame {
  public static void main(String[] args) {
    new CustomIcons();
  private ImageIcon customOpenIcon           = new ImageIcon("1.gif");
  private ImageIcon customClosedIcon      = new ImageIcon("2.gif");
  private ImageIcon customLeafIcon           = new ImageIcon("3.gif");
  public CustomIcons() {
    super("JTree Selections");
//   WindowUtilities.setNativeLookAndFeel();
//   addWindowListener(new ExitListener());
    Container content = getContentPane();
    content.setLayout(new FlowLayout());
    DefaultMutableTreeNode root =
      new DefaultMutableTreeNode("Root");
    DefaultMutableTreeNode child;
    DefaultMutableTreeNode grandChild;
    for(int childIndex=1; childIndex<4; childIndex++) {
      child = new DefaultMutableTreeNode("Child " + childIndex);
      root.add(child);
      for(int grandChildIndex=1; grandChildIndex<4; grandChildIndex++) {
        grandChild =
          new DefaultMutableTreeNode("Grandchild " + childIndex +
                                     "." + grandChildIndex);
        child.add(grandChild);
    JTree tree1 = new JTree(root);
    tree1.expandRow(1); // Expand children to illustrate leaf icons
    JScrollPane pane1 = new JScrollPane(tree1);
    pane1.setBorder(BorderFactory.createTitledBorder("Standard Icons"));
    content.add(pane1);
    JTree tree2 = new JTree(root);
    tree2.expandRow(2); // Expand children to illustrate leaf icons
    DefaultTreeCellRenderer renderer2 = new DefaultTreeCellRenderer();
    renderer2.resize(100, 100);
    renderer2.setOpenIcon(null);
    renderer2.setClosedIcon(null);
    renderer2.setLeafIcon(null);
    tree2.setCellRenderer(renderer2);
    JScrollPane pane2 = new JScrollPane(tree2);
    pane2.setBorder(BorderFactory.createTitledBorder("No Icons"));
    content.add(pane2);
    JTree tree3 = new JTree(root);
    tree3.expandRow(3); // Expand children to illustrate leaf icons
    DefaultTreeCellRenderer renderer3 = new DefaultTreeCellRenderer();
    //renderer3.setPreferredSize(new Dimension(100, 100));
    renderer3.setOpenIcon(customOpenIcon);
    renderer3.setClosedIcon(customClosedIcon);
    renderer3.setLeafIcon(customLeafIcon);
    tree3.setCellRenderer(renderer3);
    JScrollPane pane3 = new JScrollPane(tree3);
    pane3.setBorder(BorderFactory.createTitledBorder("Custom Icons"));
    content.add(pane3);
    pack();
    setVisible(true);
}

Thanks,
I declare as :
  private ImageIcon customOpenIcon           = new ImageIcon("com/aa/1.gif");
  private ImageIcon customClosedIcon      = new ImageIcon("com/aa/2.gif");
  private ImageIcon customLeafIcon           = new ImageIcon("com/aa/3.gif");but which method for customOpenIcon can be used as scale its size??
Is it
customOpenIcon.getImage().SCALE_AREA_AVERAGING;??
why show red??
I checked these, cannot find it, can you advice more or I select a wrong component??
Thank
sunny

Similar Messages

  • Resizing the icons in the dock

    Can anyone tell me how to resize the icons in my dock, they appear too small for my liking? I have omitted a bunch to give more space but this has made no difference. Any pointers would be appreciated. Ta.

    Here's the quick way to resize the Dock:
    The separator bar to the right of your Application icons can be dragged up and down.
    Also try holding Option while dragging if you want it to snap to preset sizes.

  • How to remove the icon of java in JDialog?

    How to remove the icon of java in JDialog, and change it to my own icon.

    Please make the extra effort to write out words such as "please" and "your". The extra keystrokes won't cost much in the way of time, and the enhanced clarity will be appreciated by those communicating on a forum with international readership.

  • 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 of coffee on the titile bar

    Hi!
    I am having this problem that
    how to change the icon of coffee on the titile bar
    if someone know how please respond
    Asif

    Next time please post your question in the appropriate forum, since this forum discusses the Java3D API.
    The answer is use the Frame.setIconImage method.

  • How to change the Icon for a JFileChooser ?

    Has anyone figured out how to change the icon for an instance of JFileChooser from the coffee cup to something else?
    I'm on 1.4
    Thanks,
    Ken

    Never mind. I figured it out.
    You have to use an instance of JFrame in the call to showXxxxDialog(Component c). Set the icon of the JFrame to what you want the JFileChooser's icon to be.

  • How to increase the icons of creative cloude ? The icons permanecm very small and can not see properly.

    How to increase the icons of creative cloude ? The icons permanecm very small and can not see properly.

    Hold down Control and scroll down with the mouse or trackpad.
    Regards,
    Captfred
    That's the screen zoom function activated by CNTL scroll up to zoom and CNTL-Scroll down to unzoom.

  • How to create the ICONS and SYMBOLS

    how to create the ICONS and SYMBOLS
    Title was edited by:
            Alvaro Tejada Galindo

    HI,
    Check this sample code....Not mine...
    REPORT SHOW_ICONS.
    TABLES: ICON.
    INCLUDE <ICON>.
    FIELD-SYMBOLS: <F>.
    SELECT * FROM ICON.
       ASSIGN (ICON-NAME) TO <F>.
       WRITE:   /(5) <F>, 20 '@',21 ICON-ID+1(2),23 '@',ICON-OLENG,
                ICON-BUTTON,ICON-STATUS,ICON-MESSAGE,ICON-FUNCTION,
                ICON-NAME.
    ENDSELECT.
    Also Try this,
    INCLUDE <symbol>.
    INCLUDE <icon>.
    Write:/ 'Phone Symbol:', SYM_PHONE AS SYMBOL.
    SKIP.
    WRITE: / 'Alarm Icon: ', icon_alarm AS ICON.
    For more information check out the following link it will help you.
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9e4a35c111d1829f0000e829fbfe/content.htm
    Regards,
    Padmam.

  • How to display the icons of apk files in windows explorer

    How to display the icons of apk files(android apps) in windows explorer by default in windows 7 and windows 8.1 ?

    Believe it or not; The answer is found by searching the internet.  One solution is to install an application called BlueStacks player which appears to install an Android VM for playing Android apps.  I'm sure there are other solutions, but the
    BlueStacks player looks exactly like mu Moto G screen.  The apps icons are displayed in Windows Explorer with BlueStacks installed.
    http://www.bluestacks.com/app-player.html
    I searched the internet for open apk file on pc
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”

  • How to change the icon of the news in Portal?

    Do you know how to change the icon of the news in Portal?
    I use NewBrowser to Browser the news, but I think the Icon of the News is not good,I want change it ? what should I do?
    Thanks for your help!

    Hi,
    if you are talking about the NewsBrowser of Knowledge Management (Content Management -> Explorer -> News), you should see a button "Edit" on the right side of the news.
    Press this button and fill in a new URL in the input field "Image URL". After saving the new settings, the new image should be displayed.
    Kind regards,
    Ralf

  • How to change the icon of JOptionPane and JFileChooser in swing

    Hi,
    Does any body know how to change the icon of JOptionPane and JFileChooser in swing.
    Please help me out in this.
    Thanx in advance.

    Try this
    import javax.swing.*;
    import java.awt.event.*;
    public class Untitled4 {
      public Untitled4() {
      public static void main(String[] args) {
        ImageIcon i = new ImageIcon("C:/TestTree/closed.gif");
        JOptionPane p = new JOptionPane();
        p.setMessage("This JOptionPane has my icon");
        p.setMessageType(JOptionPane.QUESTION_MESSAGE);
        p.setOptionType(JOptionPane.YES_NO_CANCEL_OPTION);
        final JDialog d = p.createDialog("test");
        d.setIconImage(i.getImage());
        d.setVisible(true);
        d.setModal(true);
        if(Integer.parseInt(p.getValue().toString()) == JOptionPane.YES_OPTION) {
            System.out.println("You Clicked Yes");
    }

  • Guys, i want to ask on how to resize the images into 1200 pixels wide?

    Guys, i want to ask on how to resize the images into 1200 pixels wide, how to do it? and what are the step by steps on doing that? thank you!!!

    See this link: http://forums.adobe.com/docs/DOC-3691

  • How to remove the tabs such as "startnow", "Shoppings", "Games"?

    How to remove the tabs such as "startnow", "Shoppings", "Games"?

    When do you see those tabs?
    See these articles for some suggestions:
    *https://support.mozilla.com/kb/Firefox+has+just+updated+tab+shows+each+time+you+start+Firefox
    *https://support.mozilla.com/kb/How+to+set+the+home+page - Firefox supports multiple home pages separated by '|' symbols
    *http://kb.mozillazine.org/Preferences_not_saved
    See also:
    *http://kb.mozillazine.org/Session_Restore

  • HT201456 how to remove the icon Apple and Bootcam on the screen ?

    how to remove the icon Apple and Bootcam on the screen ?

    please forgive me, I usually ask question on these boards, not answer them :/ but wouldnt...
    btn.setIcon(null)do it?

  • How to resize the hard drive

    how to resize the hard drive

    You can usually find your Mac and the instructions to do so by looking it up on this page.
    http://support.apple.com/specs/

Maybe you are looking for

  • How do I outline a single cell in a numbers spreadsheet

    I am trying to emphasise the borders of a single cell in a numbers spreadsheet;  I follow all the instructions I can find in mac help, they just don't make any difference.  I may be ancient, but I can usually suss things out in time; this baffles me.

  • Issues with texlive update from 2013 to 2014 version.

    I got an error about conflicting files: Packages (2): texlive-bin-2014.34260-1 texlive-core-2014.34872-1 Total Installed Size: 350.75 MiB Net Upgrade Size: 34.54 MiB :: Proceed with installation? [Y/n] (2/2) checking keys in keyring [##############]

  • Change "to equal" to "to be greater than" in Wait for Field to equal Value"

    In Sharepoint Designer 2010, in the workflow Action "Wait for Field to equal Value", I could change the "to equal" to "to be greater than". I can't find how to do this in SPD 2013. Can someone please help? Thank you!

  • How to correct distorted raw image?

    The image i took was one of my desktop accessories from about one ft. away  and at 24mm wide angle.  in the image"s  four corners is the black edges of the lens.(raw one)  Also the front edge of the desk is curved inwards and i have some bowing of th

  • How can the submitter get a copy of the FormCentral form they completed on their tablet?

    I am able to distribute a FormCentral form and view their responses. But how can they get a copy of the FormCentral form? I see how they can get an Email submission receipts with their answer, but not how they can keep a copy of the PDF form and thei