How to Use different icons for JTree in the same level

Hi guys, i come cross a problem with JTree. The module need a JTree which need to represent items in the same level using different icons. For example:
[Icon for Root]Root
|
|_____________[Icon for Table] TABLES
|
|_____________[Icon for Index] INDEXS
|
|_____________[Icon for Views] VIEWS
As i know, the default behavior for JTree is using the same icon for all leaves and
the same icon for all node that has children. How can i achieve that?
Thansk a lot!

subclass DefaultTreeCellRenderer. if you overwrite the method below, then you can set the icon to whatever you want....!
    public Component getTreeCellRendererComponent(JTree tree, Object value,
                                boolean sel,
                                boolean expanded,
                                boolean leaf, int row,
                                boolean hasFocus) {
     String         stringValue = tree.convertValueToText(value, sel,
                           expanded, leaf, row, hasFocus);
        this.tree = tree;
     this.hasFocus = hasFocus;
     setText(stringValue);
     if(sel)
         setForeground(getTextSelectionColor());
     else
         setForeground(getTextNonSelectionColor());
     // There needs to be a way to specify disabled icons.
     if (!tree.isEnabled()) {
         setEnabled(false);
         if (leaf) {
          setDisabledIcon(getLeafIcon());
         } else if (expanded) {
          setDisabledIcon(getOpenIcon());
         } else {
          setDisabledIcon(getClosedIcon());
     else {
         setEnabled(true);
         if (leaf) {
          setIcon(getLeafIcon());
         } else if (expanded) {
          setIcon(getOpenIcon());
         } else {
          setIcon(getClosedIcon());
        setComponentOrientation(tree.getComponentOrientation());
     selected = sel;
     return this;
    }

Similar Messages

  • How to use 2 webcam for java at the same time?

    hi there,
    I have a question to ask regarding webcam and java. Basically i want to know whether is it possible to have 2 web cam running in java at the same time? I have no problem when running one usb webcam since i m using "
    ml = new MediaLocator("vfw://0") ;
    what parameter must i use to specify when using 2 web cam
    many thanks
    sun

    Hi
    I am making a project in which i have to capture a image through webcam. How can I do it will you please guide me or if can provide me code. Many thanks for your support. My email id is [email protected]

  • How to use different pageFormats while printing in the same book object.

    Hi All,
    I m able to print Multiple pages, but the problem is when i want print multple pages with different pageformates I mean One pages having 4X2" size and another one is 5X5", while print second page objects not appears properly
    Pls see the below code to get the problem.
    any works around this will be appreciated.
    import java.awt.BasicStroke;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.geom.Rectangle2D;
    import java.awt.print.Book;
    import java.awt.print.PageFormat;
    import java.awt.print.Paper;
    import java.awt.print.Printable;
    import java.awt.print.PrinterJob;
    public class MultiplePageFormatTest
    public static void main(String[] args)
      MultiplePageFormatTest example3 = new MultiplePageFormatTest();
      System.exit(0);
    private final static int POINTS_PER_INCH = 72;
    public MultiplePageFormatTest()
      PrinterJob printJob = PrinterJob.getPrinterJob();
      Book book = new Book();
      PageFormat documentPageFormat = new PageFormat();
      PageFormat documentPageFormat1 = new PageFormat();
      Paper paper = new Paper();
      Paper paper1 = new Paper();
      paper.setSize(4.5 * POINTS_PER_INCH, 2.5 * POINTS_PER_INCH);
      paper.setImageableArea(.25 * POINTS_PER_INCH, .25 * POINTS_PER_INCH,
       4 * POINTS_PER_INCH, 2 * POINTS_PER_INCH);
      documentPageFormat.setPaper(paper);
      paper1.setSize(5.5 * POINTS_PER_INCH, 5.5 * POINTS_PER_INCH);
      paper1.setImageableArea(.25 * POINTS_PER_INCH, .25 * POINTS_PER_INCH,
       5 * POINTS_PER_INCH, 5 * POINTS_PER_INCH);
      documentPageFormat1.setPaper(paper1);
      book.append(new Document(), documentPageFormat);
      book.append(new Document(), documentPageFormat1);
      printJob.setPageable(book);
      if (printJob.printDialog())
       try
        printJob.print();
       catch (Exception PrintException)
        PrintException.printStackTrace();
    private class Document implements Printable
      public int print(Graphics g, PageFormat pageFormat, int page)
       Graphics2D g2d = (Graphics2D) g;
       g2d.translate(pageFormat.getImageableX(), pageFormat
        .getImageableY());
       g2d.setPaint(Color.black);
       g2d.setStroke(new BasicStroke(
        2));
       Rectangle2D.Double border = new Rectangle2D.Double(
        0, 0, pageFormat.getImageableWidth(), pageFormat
         .getImageableHeight());
       g2d.draw(border);
       return (PAGE_EXISTS);
    }

    Hi,
    Till now this question is not answered.........
    Any Answer around this deeply apprciated.
    Edited by: DoraiRaj on Sep 29, 2009 3:55 AM

  • How to display different icon, for different node of jtree

    Hi All,
    How to display different icon, for different node of jtree

    you haven't responded to my last post here: [http://forums.sun.com/thread.jspa?threadID=5323190&messageID=10382676#10382676|http://forums.sun.com/thread.jspa?threadID=5323190&messageID=10382676#10382676]

  • How to set different Icons for Jtreenode

    How to set different Icons for Jtreenode,i want to set icons for jtreenode,not only for leaf,open,closeicon,i hope that each node has a different icon.Thanks!

    you need to check for the node value within a renderer, then assign an icon based on what you expect to get back.
    check out this page. http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html

  • How to set different icons for different windows which is seen in the top left corner?

    Hi
    How to set different icons for different windows which is seen in the top left corner? I know when building exe there is a option to edit icons or add icons and that icon is default for all the windows in the project. But i want different icons for different windows which is possible in VB.
    Is there any way to set icon by calling any dlls.
    Thanks & Regards
    Samuel J
    [email protected]

    Hi Sam,
    no problem. See the attachment.
    Mike
    Attachments:
    TestIcon_LV85.zip ‏44 KB

  • Can anyone give me simple instructions on how to use more than one ipod on the same computer with itunes? Both my daughters have ipods, my wife has one

    Dear All
    Can anyone give me simple instructions on how to use more than one ipod on the same computer with itunes. My daughters have a different generation 'nano' each & my wife a 'shuffle'?
    Many thanks

    Click here for options.
    (69081)

  • HT3130 trying to export a 4 minute video to desktop.  Only 1:08 seconds exports.  I've tried other clips and they all cut at 1:08.  Used different exports like Quicktime with the same results.

    trying to export a 4 minute video to desktop.  Only 1:08 seconds exports.  I've tried other clips and they all cut at 1:08.  Used different exports like Quicktime with the same results.

    Good to hear that you've had some success with the import.
    I tried 3 times to do it before I finally changed it to H.264, and it worked on the first try.  The quality of the compression was terrible with those settings compared to my standard settings, but I'm just glad it worked.
    Rather than Share>Export using QuickTime and then choosing your own settings for H.264, you may get a better result if you simply use the Share>Export Movie option. Alternatively, use the Share>Media Browser option (as I mentioned in my earlier post). You will be presented with a range of sizes to choose from. Depending on your target, it's usually best to select the highest size available, such as Large, HD 720p or HD 1080p. However, for producing a DVD it's best to not go beyond the HD 720p size, as the DVD will be downscaled during encoding to Standard Definition in the appropriate size for either PAL or NTSC.
    In my experience, both these options (Export Movie or Media Browser) produce a video file of excellent quality. The files will be in H.264 format and will have the file extension .mov or .m4v depending on the size of the export. I'm assuming that your camera records HD video in AVCHD format.
    These files work well with iDVD (or other DVD authoring programs). The export process for the presets is optimised by Apple to produce high quality video files at a reasonable file size. So, selecting a preset may give you a much better result. Choosing your own H.264 settings when using the "Export using QuickTime" method could be why "the compression was terrible". You may have selected a data (bit) rate that was too low. There is always a trade-off between quality and file size when compressing video.
    So, to summarise, try one of the Apple presets using either Share>Export Movie or Share>Media Browser.
    John

  • How to use parallel flowed subforms begining at the same position.

    How to use parallel flowed subforms begining at the same position in my form.
    Ex
    Subform1
    Subform2
    Subform3
    DropDownList1
    DropDownList1
    DropDownList1
    I would like to repeat  with a button the 3 subforms in parallel
    Subform1
    Subform2
    Subform3
    DropDownList1
    DropDownList1
    DropDownList1
    Subform1
    Subform2
    Subform3
    DropDownList1
    DropDownList1
    DropDownList1

    Post your question in the LiveCycle Designer forum.

  • HLOC Chart: How to use different stroke for different items in a HLOCSeries?

    I want to use different color for the stroke in a HLOC chart based on the openfield, closefiled value.
    It's just like the fillFunction in a ColumnSeries.
    Anybody got any ideas to make this?
    And I would also like to know which class is responsible for the drawing of charts? So that I can alter it and develop one that suits my needs.
    Thanks very much!

    Natasha, thanks!
    I need to override the updateDisplayList function in HLOCItemRenderer to make it draw what I want.

  • How to apply different styles to Portlets on the same Portal page?

    How do you apply different styles to Portlets on the same Portal page?
    I'm new to this kind of thing, but understand that something called "cascading style sheets" can help here?
    What are these, how do you use them, and can you make different Portlets (all types - PL/SQL, Java, Applications, etc) on the same Portal page have different styles assigned?
    Thanks!

    Jeff,
    Apply Oracle Portal styles at the region level. Your portlets within each region will inherit the style defined for the region.
    You may want to check out Report #40050 at portalcenter.oracle.com, "Design an Attractive and Compelling Portal Interface" for a good overview of the various design features of Oracle Portal.
    Here is the link:
    http://portalcenter.oracle.com/pls/ops/docs/FOLDER/COMMUNITY/OTN_CONTENT/MAINPAGE/OWSF_2003_PAPERS/40050_STOVER.PDF
    Regards,
    Jay

  • How to set different icon for different type of document

    Hi,
    In my repository, we have different kinds of document (crystal report, word document, excel, jpg ...) and we wanna show specific icon for each kind. In my used ResourceRender I cann't see where to change (rnd:icon?)
    Could someone tell me how to achieve that? Thanks
    Ray

    Hi Ray Li,
    in KM icons are mapped to mime types. You can add a mapping or change an existing one as follows:
    1. Go to Systemadministrarion - System Configuration - Knowledge Management - Content Management - Utilities - Icons
    2. Add your mime mapping or change an existing one. To determine the correct mime type of your documents, just have a look at the details dialog in KM.
    3. The path to the icons points (by default) to following directory on your KM server: usr\sap\SID\SYS\global\config\cm\etc\public\mimes\images
    Here you can replace images or add some new.
    Hope this helps,
    Carsten
    Seems like somebody thought the same thought bit faster than I did. Would like to delete my answer that does not contain any additional info. But dunno how to.
    Message was edited by: Carsten Buechert

  • How to use different stylesheets for ChangeAttributeRequest workflow in OAM

    Hi,
    We have a requirement to invoke different change attribute request workflows (change password ,change email etc..) from external JSPs..
    I want to apply different stylesheets for each workflow. In the workflow URL if i enter style=stylesheet-name its not using that stylesheet. Always its using the same base stylesheet (wf_changeattr.xsl). How can i use different stylesheets? Any pointers on this is appreciated.
    Thanks inadvance..
    Regards,
    Srikanth

    Hi Colin,
    Thanks for your response. Now i am able to invoke different xsls for different workflows.
    I did a mistake by entering style=stylesheet-name. I verified the same with xsl=stylesheet-name.
    Its working fine now..
    Thanks & Regards,
    Srikanth

  • How to use different iViews for variables and queries?

    Hi all!
    I need to use separtate iViews for storing variables and extracting queries.
    For example, I have one variable "Currency" for two different queries,  and I need that all of these queries (in separate iViews) would use the value of currency was put by user in the first iView with only one input.
    How can I do this task? Is it possible at all?
    Thanks for replies.

    Hello Alex,
    You have to use EP client framework (EPCF) in your development.
    I hope this idea will help you.
    Kind regards, Pino.

  • How do use different formatting for a distinct "Section"

    I have experienced formatting problems with an older document after upgrading to Pages 2.
    There was a distinct "section" within that document with a different "top" and "bottom" border. I find myself unable to change the top and bottom borders within just the Section I want to revise. When I try dragging the ruler on the page in question, it changes the settings for the entire document.
    Questions:
    (1) How do I ensure that one of my document's pages is, in fact, a distinct Section with its own formatting?
    (2) How can I change the page setup of that Section independently of the rest of the document?
    PowerMac G5 dual 2.0   Mac OS X (10.4.4)  

    Hello David,
    now I'm back for your problem. You are right: the settings "Before" and "After" of the Layout Inspector are only for the areas at the Layout Breaks unlike the "Left" and "Right" number fields. If you have long Sections you have to use a workaround.
    You have to insert a placeholder at the top and at the bottom of the pages to "simulate" the wider margins. But don't be frightened, you don't have to do it for every page. For that, Pages has the Section Master.
    If you have a "Facing Pages" document, place rectangles (the placeholders) with no outline and with no filling at the top and at the bottom of a left and a right page. This rectangles should be adjusted in that way, so they have the same width like the text area and the same height you want to have for the wider Margins. Give the placeholder the "Fixed on page" setting in the Wrap Inspector and no "Extra Space". If you have a none "Facing Pages" document, you have to position the placeholder only on the top and the bottom of one page. Please notice the settings "First page is different" and "Left and right pages are different" of the Layout Inspector.
    After you have placed the rectangles, select them and choose the menu item "Format/Advanced/Move Object to Section Master". Now you have the space at the top and the bottom of every page in that Section. Only the Section with the oversized images may not have the placeholders.
    Excuse me, that I haven't mentioned the workaround the first time, but to write the Layout Border thing. I have forgotten that only the "Left" and "Right" border settings are for all pages.
    Frank.

Maybe you are looking for

  • Creating a symlink directory on a network share to a path below a mapped drive letter, local path, or UNC path does not work

    Am I correct in assuming I can not create a `symlinkd` to a network share, local path, or a UNC path on a network share that will be accessible by clients? ###Mapped drive letters don't work: 1) navigate to a network share: pushd \\windows2008server\

  • How to make a field in Sales order as Display

    Hi Friends, I want to make the field pricing date in sales order as display only. Currently the field is changeable. Can someone please tell me how can i do this. Regards, Wasim.

  • How to resolve Collision in MAS 4.0

    Hi All I need help on this. We are 2 developers both of us unknowigly made some changes to the same tile in 2 diffrent changlists. we are ready to release with lot of additional changes in the change list. It gives an collision error. We don't want t

  • How to Upgrade Solaris Package ?

    Hi, I created a solais package (*.pkg), which I've installed with the following command: "pkgadd -d mypkg.pkg" 1. What command should I use in order to upgrade it to a higher version? 2. What are the changes I have to do in the installation pkg for s

  • Can I use Photoshop cs (Mac) on my OS 10.9.3 system

    When I attempt to install an old Photoshop CS on my never Mac computer with an OS10.9.3 system I get a message indicating that I cannot open the application "Install Adobe Photoshop CS.app" because Power PC applications are no longer supported.    Is