How to display multiple JComponents in a tree cell renderer

I have an object in a tree cell renderer and want to display its members(three members) status in a JTree as checkboxes such that each node displays three checkboxex with member-names and a node name. i tried using a JPanel and adding three labels into this panel to be returned for the cell renderer but the GUI fails to paint the node componnents. However on clicking the node the component which isn't visible displays correctly. please Help me out

Since you didn't provide any sample code, it's all about wild guesses on what your problem is. The following code shows the type of program you could have posted :import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
public class TestTree extends JPanel {
     private static class MyCell {
          String theCellName;
          boolean theFirstField;
          boolean theSecondField;
          boolean theThirdField;
          public MyCell(String aName, boolean firstField, boolean secondField, boolean thirdField) {
               theCellName = aName;
               theFirstField = firstField;
               theSecondField = secondField;
               theThirdField = thirdField;
     private static class MyTreeCellRenderer extends JPanel implements TreeCellRenderer {
          private JLabel theCellNameLabel;
          private JCheckBox theFirstCheckBox;
          private JCheckBox theSecondCheckBox;
          private JCheckBox theThirdCheckBox;
          private DefaultTreeCellRenderer theDelegate;
          public MyTreeCellRenderer() {
               super(new GridLayout(4, 1));
               theCellNameLabel = new JLabel();
               add(theCellNameLabel);
               theFirstCheckBox = new JCheckBox("firstField");
               add(theFirstCheckBox);
               theSecondCheckBox = new JCheckBox("secondField");
               add(theSecondCheckBox);
               theThirdCheckBox = new JCheckBox("thirdField");
               add(theThirdCheckBox);
               theDelegate = new DefaultTreeCellRenderer();
               setOpaque(true);
          public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
                                                                   boolean expanded, boolean leaf, int row, boolean hasFocus) {
               if (!(value instanceof DefaultMutableTreeNode)) {
                    return theDelegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
               Object userObject = ((DefaultMutableTreeNode)value).getUserObject();
               if (!(userObject instanceof MyCell)) {
                    return theDelegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
               setBackground(tree.getBackground());
               if (selected) {
                    setBorder(BorderFactory.createLineBorder(Color.BLUE, 2));
               } else {
                    setBorder(BorderFactory.createLineBorder(getBackground(), 2));
               MyCell cell = (MyCell)userObject;
               theCellNameLabel.setText(cell.theCellName);
               theFirstCheckBox.setSelected(cell.theFirstField);
               theSecondCheckBox.setSelected(cell.theSecondField);
               theThirdCheckBox.setSelected(cell.theThirdField);
               return this;
          public Component add(Component comp) {
               if (comp instanceof JComponent) {
                    ((JComponent)comp).setOpaque(false);
               return super.add(comp);
     public TestTree() {
          super(new BorderLayout());
          JTree tree = new JTree(createModel());
          tree.setShowsRootHandles(true);
          tree.setCellRenderer(new MyTreeCellRenderer());
          add(new JScrollPane(tree), BorderLayout.CENTER);
     private static final TreeModel createModel() {
          DefaultMutableTreeNode root = new DefaultMutableTreeNode(new MyCell("root", true, true, true));
          DefaultMutableTreeNode child1 = new DefaultMutableTreeNode(new MyCell("child1", false, true, false));
          DefaultMutableTreeNode child2 = new DefaultMutableTreeNode(new MyCell("child2", false, false, true));
          root.add(child1);
          root.add(child2);
          return new DefaultTreeModel(root);
     public static void main(String[] args) {
          final JFrame frame = new JFrame("Test");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setContentPane(new TestTree());
          SwingUtilities.invokeLater(new Runnable() {
               public void run() {
                    frame.setSize(600, 400);
                    frame.show();
}

Similar Messages

  • How to Display multiple records in Table in VC without using BAPI.

    Hi All,
    I am working on Visual composer (NW2004s SP10). I am trying to display Poitems from BAPI_PO_GETDETAIL. I am creating my front end using VC. I have created one form and one Table where I want to display POItems. I am writing my logic of retrieving data from BAPI in CAF.I am connecting them in Guided procedures.When I run my process in Guided Procedures I am getting single row displayed in table. Can Anyone help me how to display multiple rows in table.
    Regards,
    Sheetal

    Hi Sheetal,
    if the BAPI returns a table, then you get multiple rows. From which system is the BAPI, so that I can check the BAPI to give you further information.
    Best Regards,
    marcel

  • How to display multiple attachments in UWL item in portal?

    HI,
    How to display multiple attachments in UWL item in portal?
    I want to display more than one attachment in UWL body,present its dispalying one attachment.
    Pls help on this
    Thanks,
    Bheem
    Edited by: v bheem on Aug 4, 2009 3:10 PM

    Hi,
    Are you able to manage this! Pls do let us know if you have done any configuration changes!

  • How to display multiple thumbnail images in jframe

    hi
    please help me about how to display multiple thumbnail images in jframe

    Multi post:
    http://forum.java.sun.com/thread.jspa?threadID=627253&messageID=3588990

  • How to display multiple tables from database using netbeans swing gui

    plz reply asap on how to display multiple tables from database using netbeans swing gui into the same project

    Layered Pane with JTables or you can easily to it with a little scripting and HTML.
    plzzzzzzzzzzzzzzzzz, do not use SMS speak when posting.

  • How to display multiple reports at the same time

    Hi,
    I'm trying to display multiple reports at the same time, each one in separates tabs or windows using Forms 11g 11.1.1.6
    I have a button which has a call to a procedure which makes use of rp2rro library to show the specific reports, for example:
    call_report('report1');
    call_report('report2');
    call_report('report3');
    call_report('report4');
    The main problem is that, just the last report is been displayed.
    Is there some way to display report1, report2 etc in separate tabs or windows ??
    Regards
    Carlos

    You shouldn't have a problem calling different reports at once. As long as you're using Forms 11g they show up in different windows.
    The question is how you are calling the report.
    Here is how I manipulate it.
    After I pass parameters with the ADD_PARAMETER built-in I set some key values (destype, desformat, desname) with the RP2RRO's procedures.
    Finally calling RP2RRO.RP2RRO_RUN_PRODUCT and then WEB.SHOW_DOCUMENT passing the correct procedure parameters the report comes up in a window. If you repeat the above changing the appropriate variables (the report_name in the RP2RRO_RUN_PRODUCT and so on) you can get multiple reports in different windows.

  • How to display multiple categories of webapp items in list view? Changing listbox list to checkbox list to select category in submission process?

    Hello!
    1.
    I am trying to get my page to list webapp items that are part of a few categories. I understand that if i want to view only one category, I just need to do the normal process of choosing that category and placing it out. So my question is: How do I display multiple categories of items in a webapp in a single page. I've tried this
    {module_webapps,WEBAPP_ID,c,CATEGORY_ID1,,,,10,,1} {module_webapps,WEBAPP_ID,c,CATEGORY_ID2,,,,10,,1}
    This only displays the everything from the first category, then everything from the next, which will not make it in order of date.
    I've also tried this for fun:
    {module_webapps,WEBAPP_ID,c,CATEGORY_ID1&CATEGORY_ID2,,,,10,,1}
    How can I go about doing it?
    2.
    I am looking to allow users to input a webapp item and allow them to select a category to tie to that item.
    <label for="CAT_Category">Category (You may select more than 1)<span class="req">*</span></label>
        <select name="CAT_Category" id="CAT_Category" class="cat_listbox" rows="4" multiple="multiple" style="height: 60px;">
        <option value="CATEGORY_ID1">--- Option 1</option>
        <option value="CATEGORY_ID2">--- Option 2</option>
        </select>
    Is it possible for me to change the listbox style into a checkbox style such that the user doesn't have to control+click multiple options?

    No answer to No.1 but I really want to find it out too.
    No.2 
    If you already know list of the categories & ID you can manually create a list of checkboxes
    <input type="checkbox" name="CAT_Category" value="89081" />
    <input type="checkbox" name="CAT_Category" value="89082" />
    <input type="checkbox" name="CAT_Category" value="89083" />
    something like that should work

  • How to select multiple records from a TREE in the table

    HI,
    I have a tree structure which is in the table.When I open the node of the tree,all the subnodes are coming as one-one records in the table.I want to slect multiple record from this table.I applied onLeadSelect for this table,I can select only 1 record from the table.
    Can any one plz suggest me how to select multiple records from the table so that I can get all the data of those selected record.
    Regards
    -Sandip

    Rashmi/Kukku,
    First of all, Thanks for your help!
    Is there any other way in which we can access tables other than using BAPIs or RFCs?
    In my case, there is a table structure which has to be updated with values after validating a key. i don't think there is any RFC available now. do i need to create bapi/rfc for that?
    Krishna Murthy

  • How to display multiple selected rows in a table inside a popup?

    Hi,
    I have a table on which multiple selection is enabled. I am able to get hold of multiple selected rows i.e. i am able to iterate over the selected row keys and print their values. Now, my problem is how to display the contents of all the selected rows in a popup? I get the details of only one row when I launch the popup.
    Thanks
    Karan

    Hi,
    Not confident if this works or not but just try it...
    1. create a ViewLink between the same view Object.
    The source and destination wil be the same Vo and the source and destination attribute will be the pk of both Vos.
    2. Update the changes in Appln Module.
    Open the AM and in DataModel tab .
    select the Same VO from which you created table in the DataModel Listbox and select the VL in the "Avaible View Objects" List Box. Add under it(selected vo in datamodel listbox).
    3. Refresh DataControl accordion.
    4. in your jsff page drag and drop the child vo as a table..
    See if it works
    Regards,
    Santosh.

  • How to display multiple page images in forms ?

    Hi,
    What is the best method to display multiple pages image(100 pages) in forms 10g?
    Thanks

    Hello,
    <p>this is a link to a tutorial that contains several sample forms.<br> One of them (ALBUM.FMB) demonstrates how to display hundred of images.<br><br>The tutorial is in French, but you can simply download the samples on the introduction chapter</p>Francois

  • How to display multiple clocks in menu bar?

    Is there an app that can display multiple clocks in different time zones, side by side, like the regular system clock?
    http://d.pr/i/P6Zr

    Does this come close enough?
    https://itunes.apple.com/gb/app/clocks/id414554506?mt=12
    Found at…
    http://www.cultofmac.com/165298/set-up-multiple-world-clocks-in-menu-bar-os-x-ti ps/
    Don't forget you can add multiple clock widgets to Dashboard, and the info icon will allow you to set the location/ timezone.
    This will give you a dashboard overview…
    http://mac.appstorm.net/how-to/using-dashboard-in-2013/

  • How to display XML generated dynamically, as TREE in cluster environment

    hai guys,
    we are generating a tree.xml file in server side as follows.
    path = getServletConfig().getServletContext().getRealPath("/QBE/jsp/tree.xml");
    BufferedWriter out1 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path),"UTF8"));
    out1.write(xmlString + "</tree>");
    out1.close();
    "xmlString" holds the data in xml tag format.
    in order to display the xml file in TREE structure, we are using a function like
    function createTree()
         var tree = new WebFXLoadTree("SMQ/AMQ List", "tree.xml");
         document.write(tree);
    ALL THIS MECHANISM IS WORKING FINE IN DEVELOPMENT ENVIRONMENT ANS AS WELL AS WHEN WE DEPLOY THE RELEASE IN LOCAL MACHINE. BUT IT IS NOT WORKING WHEN THE RELEASE IS DEPLOYED IN CLUSTER ENVIRONMENT.
    Please help me out how to solve this...
    thanks in advance,
    Ranga
    Edited by: Ranganatha on Jun 5, 2008 5:18 AM

    Hey if you want any more information regarding this problem, i can provide.

  • HT201300 how activation display multiples in macbook pro 13

    how activation arrange multiple display

    Hi pattyufita,
    Depending on what model of MacBook Pro you have, you will need the correct adapter for its video out port. Also, the other end of the adapter would need to fit whatever video in port your TV has. So for example the most recent MacBook Pro has Thunderbolt for video out and your TV might use HDMI video. See the specifications on this page for the MacBook Pro -
    Apple - MacBook Pro with Retina display - Technical Specifications
    http://www.apple.com/macbook-pro/specs-retina/
    Of course you will need to find the specifications for your own model of MacBook Pro. You can find out which model you have by going to the Apple menu and selecting About this Mac and clicking the More Info button.
    Thanks for using Apple Support Communities.
    Best,
    Brett L

  • Hi , How to display multiple images

    hi,
    please help me out!
    I need to display multiple images on the jframe or on a jpanel . From the database where the path of the images are stored how to do it any one please
    give the code

    import java.awt.*;
    import java.awt.geom.AffineTransform;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import java.net.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class ShowingImages extends JPanel
        final int
            WIDTH  = 75,
            HEIGHT = 125;
        public ShowingImages()
            String[] filePaths = getPaths();
            BufferedImage[] images = getImages(filePaths);
            setLayout(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(5,5,5,5);
            gbc.weighty = 1.0;
            gbc.weightx = 1.0;
            loadImages(images, gbc);
        private void loadImages(BufferedImage[] images, GridBagConstraints gbc)
            for(int j = 0; j < images.length; j++)
                BufferedImage scaled = scale(images[j], WIDTH, HEIGHT);
                ImageIcon icon = new ImageIcon(scaled);
                if(j % 2 == 0)
                    gbc.gridwidth = GridBagConstraints.RELATIVE;
                else
                    gbc.gridwidth = GridBagConstraints.REMAINDER;
                add(new JLabel(icon), gbc);
        private String[] getPaths()
            String[] fileNames = {
                "images/redfox.jpg", "images/greathornedowl.jpg",
                "images/bclynx.jpg", "images/mtngoat.jpg"
            return fileNames;
        private BufferedImage[] getImages(String[] fileNames)
            BufferedImage[] images = new BufferedImage[fileNames.length];
            for(int j = 0; j < fileNames.length; j++)
                images[j] = loadImage(fileNames[j]);
            return images;
        private BufferedImage loadImage(String fileName)
            BufferedImage image = null;
            try
                URL url = new URL("file:" + fileName);
                image = ImageIO.read(url);
            catch(MalformedURLException mue)
                System.err.println("malformed url for image: " + mue.getMessage());
            catch(IOException ioe)
                System.err.println("unable to read image file: " + ioe.getMessage());
            return image;
        private BufferedImage scale(BufferedImage source, int w, int h)
            BufferedImage scaled = new BufferedImage(w, h, source.getType());
            Graphics2D g2 = scaled.createGraphics();
            g2.setPaint(getBackground());          // background for
            g2.fillRect(0,0,w,h);                  //   scale to fit
            double width = source.getWidth();
            double height = source.getHeight();
            double xScale = w / width;
            double yScale = h / height;
            double scale = Math.min(xScale, yScale);      // scale to fit
            //double scale = Math.max(xScale, yScale);    // scale to fill
            double x = (w - scale*width)/2;
            double y = (h - scale*height)/2;
            AffineTransform at = AffineTransform.getScaleInstance(scale, scale);
            g2.translate(x, y);
            g2.drawRenderedImage(source, at);
            g2.dispose();
            return scaled;
        public static void main(String[] args)
            // create and configure your JFrame here...
            f.getContentPane().add(new JScrollPane(new ShowingImages()));
    }

  • Crystal report -How to display multiple lines in line chart?

    Hi,
    M struggling to display multiple lines in line chart. All the values m fetching it from database into data table in below format & data type
    Category(String).....year(Int).....graph_values(Int).....table_value(String)
    Test.........................2006.......... -100............................(100)
    Avg..........................2006..........20................................20
    Median......................2006...........5................................5
    Test..........................2007...........500.............................500
    Avg...........................2007............90..............................90
    Median.......................2007............45..............................45
    M using cross tab to display data and chart to plot line. Following fields I used in Cross tab Expert & Chart expert
    Cross tab expert-
    Rows u2013 category
    Columns u2013 year
    Summarized fields u2013 Min of table_value
    In Chart Expert u2013
    On Change of - Year
    Show values - graph values
    In cross tab m able to see the data properly but not in graph.I have three categories. Hence it should plot three lines in line chart but m able to see only one line for test category.
    FYI u2013 using VS 2008 and crystal report assembly version 10.5
    Urgent. Please reply soon.
    Thanks
    ThakurS

    I got the solution.
    In Chart Expert - I should use
    On Change of -- Year, Category
    Show values -- graph values
    Thanks,
    ThakurS

Maybe you are looking for