JPanel as TreeCellRenderer not shown

Hello all,
I'm experiencing a rather strange problem using a custom JPanel as a TreeCellRenderer for a JTree. Basically I needed to show a JLabel and an JTextArea inside a JScrollPane for each Node in my JTree. So I created a subclass of JPanel, implementing the TreeCellRenderer interface and registered it on the tree. The problem I experience is, that nothing is shown in my tree. Instead of the JPanel and its components I see a white space exactly the size of the JPanel, but no components in it. When I try to add my custom JPanel to a regular other panel, it shows up perfectly. My source code for the renderer looks like this (the text is statically provided at the moment, so each node should display the same amount of information):
public class XMLTreeCellRenderer extends JPanel implements TreeCellRenderer
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private void initComponents()
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel1.setOpaque(true);
        jLabel1.setHorizontalAlignment(SwingConstants.LEFT);
        jLabel1.setVerticalAlignment(SwingConstants.CENTER);
        setLayout(new java.awt.BorderLayout(10, 10));
        setOpaque(true);
        setBackground(new java.awt.Color(255, 255, 255));
        setMinimumSize(new java.awt.Dimension(140, 100));
        jPanel1.setLayout(new java.awt.BorderLayout(10, 10));
        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setPreferredSize(new java.awt.Dimension(140, 20));
        jLabel1.setBackground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Testvalue");
        jPanel1.add(jLabel1, java.awt.BorderLayout.CENTER);
        add(jPanel1, java.awt.BorderLayout.NORTH);
        jPanel2.setLayout(new java.awt.BorderLayout(10, 10));
        jPanel2.setPreferredSize(new java.awt.Dimension(140, 80));
        jScrollPane1.setBorder(new javax.swing.border.EtchedBorder());
        jTextArea1.setEditable(false);
        jTextArea1.setToolTipText("Current Value");
        jScrollPane1.setViewportView(jTextArea1);
        jPanel2.add(jScrollPane1, java.awt.BorderLayout.CENTER);
        add(jPanel2, java.awt.BorderLayout.CENTER);
        validate();
        repaint();
    public XMLTreeCellRenderer()
        super();
        initComponents();
     * Returns the component that contains a rendered version of this node
     * @see javax.swing.tree.TreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean)
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
        LineBorder m_border;
        m_border = new LineBorder(Color.RED, 1, true);
        if (selected)
            setBorder(m_border);
        else
            setBorder(null);
        return this;
}This is really driving me crazy. If I'm trying to return a simple JLabel, everything works ok, but whenever I want to show the JPanel, nothing happens.
Thanks in advance for any suggestions,
Sven

Hello,
no, I did not set a preferred size for the border; I did as shown in the code:
        m_border = new LineBorder(Color.RED, 1, true);
        if (selected)
            setBorder(m_border);
        else
            setBorder(null);
        }The only thing that I do is setting a minimum size.
Sven

Similar Messages

  • Why JPanel loaded is not shown up immediately???

    Dear Friends:
    I have a JPane to dynamically load other different JPanel at run time according to My click on different Tab, but my problem is that when I click the each diff Tab, the JPanel loaded is not shown up immediately,
    I must minimize whole application, then restore back to its original size, the loaded JPanel will show up,
    I used repaint() at the end of each loading, but did not take effect,
    How to solve this problem??
    Thanks
    sunny

    After add or removing components from a panel on a visible GUI you need to revalidate() the panel, so the LayoutManager can be invoked.

  • New images not shown

    Hi,
    Apparently images that are not on the disk when a Java application starts but that are added on disk during program execution, are not shown on JLabels, JButtons, ...
    Anyone knows why?
    Taaje

    Dunno, coz it works 4 me. Y ! 4 u?
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    import javax.imageio.*;
    import javax.swing.*;
    public class Example {
        public static void main(String[] args) {
            final File file = new File("temp.jpg"); //constructor doesn't create file in file system, right?
            final JPanel cp = new JPanel(new BorderLayout());
            JButton write = new JButton("write image file");
            write.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent evt) {
                    try {
                        URL url = new URL("http://today.java.net/jag/bio/JagHeadshot-small.jpg");
                        ImageIO.write(ImageIO.read(url), "jpg", file);
                    } catch (IOException e) {
                        e.printStackTrace();
            JButton read = new JButton("attempt to read file and create label");
            read.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent evt) {
                   try {
                       cp.add(new JLabel(new ImageIcon(ImageIO.read(file))));
                       cp.revalidate();
                       cp.repaint();
                   } catch (IOException e) {
                       e.printStackTrace();
            JPanel buttons = new JPanel();
            buttons.add(write);
            buttons.add(read);
            cp.add(buttons, BorderLayout.NORTH);
            cp.setPreferredSize(new Dimension(400, 300));
            JFrame f = new JFrame("Example");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setContentPane(cp);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    }

  • Why JComboBox not shown?

    I use a JPanel, and tried to show a JComboBox on it.
    But somehow the JComboBox is not shown. Need
    help here. Thank you.

    Just for fun, I wrote a small test program that included the following lines:
    modeType.addItem("Phi");
    modeType.addItem("Pump_probe delay");
    modeType.setSelectedIndex(0);
    modeType.setEnabled(true);
    modeType.setBounds(40, 150, 120, 30);
    add(modeType, null);As you can see, those lines are identical to the code you posted. modeType is a JComboBox that I'm adding to a JPanel that has no layout manager. In my program the combobox shows up perfectly.
    This tells us that the problem with your code is not those 6 lines, but something else. And without seeing the rest of your code it's awfully difficult to guess what it can be.

  • JMenu is not shown completely

    Hello.
    I've created an application with a JMenu. Now I have the problem that it is not shown completely. It's just shown the beginning until there's a JPanel and then the JPanel covers the JMenu. How can I change the program that the JMenu covers the JPanel and not reverse?
    Please help.

    Without a code sample it's difficult to be precise. However it sounds as if you may be using a borderlayout and placing the JPanel in the same area as the JMenu. For example you may have code like:container.add(menu,BorderLayout.NORTH);
    container.add(panel,BorderLayout.NORTH);

  • Modify MemoryMonitor.java - refresh even not shown

    Hi guys.
    I looked at the MemoryMonitor.java which is a class that dynamicly profile the memory usage of the system using graphics.
    The thing is that if the JPanel (frame) in the monitor is not shown, the graphics of the monitor will also not be updated.
    I have modified the code by getting rid of the fragment of "if (isShowing()" etc, it is still not updated if the window is hided behind other apps.
    Any way to force the refresh of the JPanel or Swing compenont even they are hiding?
    the MemoryMonitor.java can be found here:
    http://www.iaas.uni-stuttgart.de/lehre/SS_05/Vorlesungen/Exercise_WebbasAnwIntegration/ressourcen/exc2/java2d/MemoryMonitor.java

    The Thread that updates the data will be stopped when the window is iconified (minimised) - that will stop the repaints happening.
    Other than that, your Thread should still run alright (without the the isShowing call).
    When the window is behind other windows I suppose it's possible that the call to paint is skipped as there is no visible region to render. If you still want some code to run then you shouldn't put it in the paint method - this is for painting!
    Split the code between two methods (for example, one for calculation and one for painting). Then call your new method and repaint as previously done. This should also help tidy up the code which seems to mix up rendering logic in the animation loop and calculating in the painting method.
    Hope this helps.

  • Component not shown?

    Hi,
    Im new to the AWT (the last time I programmed a real window was when Java was in beta release. Much has changed since then). I'm trying to get a JPanel to be shown inside a JFrame. At first I worked with another layout (FlowLayout), but choose GridBagLayout. Using the FlowLayout the first time I saw noting in my window. Later I got that working. But then I had to choose for the GridBagLayout. Again nothing is showing. Eventually (hopefully) I will figure out why not.
    What I would like to ask, is there a general cause for the situation that Components are not shown? For instance, after creation of everything, never forget to call paint()?
    Abel

    One thing never to forget is a
    add(component);<%-{                                                                                                                                                                                               

  • Some fonts are not shown correctly in LabVIEW 2012

    I found a bug related with fonts in LabVIEW2012 f3 KR.
    - When I select NI7SEG in font selection dialog, right font is not shown in the example box.
    - Draw text at point.vi shows same problem for some fonts while other fonts are working.
    I reported it to Korean NI. As far as I know, this was not reported in previous versions and I couldn't find any related documents in Google. 
    So, here I would like to know whether it is related with only Korean version. Please let me know if English version is OK. 
    * OS: Windows 7 32bit KR

    Just now, I installed LabVIEW 2012 f3 (32-bit, English) and checked for the issue. But the font(NI7SEG) was not shown properly in VI either.
    - Both of Korea and English version of LabVIEW 2012 on Win 7 Korea OS shows wrong results. It is same on 64-bit OS.
    - LabVIEW 2010 but on same PC shows correct fonts.
    Is there a limit of number of fonts in LabVIEW? There are more than 100 fonts are shown in the "Selection Font" dialog and I can divide them into 3 groups by sequential order. I find that all fonts in the 3rd group are not applied correctly.
    (1st group)
    Arial Unicode MS...
    Bookshelf Symbol 3....
    Windings 3
    (2nd group)
    @Arial Unicode MS...
    @Terminal
    (3rd group)
    Arial...
    Consolas...
    Courier...  
    Licida Console... 
    NI7SEG...
    Verdana

  • IPC/VC: Knowledgebase/KB of ECC is not shown in CRM

    Hi,
    we would like to use the Variant Configuration in CRM.
    Today we are using already the IPC in a standalone environment with an external system (IPC 5.0, the external system is using the IPC in the Java environment of ERP). From the same ECC System we would like to download now the knowledge bases to reuse them in CRM 7.0. All knowledge bases and runtime environments are already available. When I download the object SCE (with certain filters), I can see all those entries in table COMM_CFGKB in CRM.
    Anyhow, when checking the material in CRM (e.g. commpr01 or WebUI), no knowledge base is shown!
    The table COMM_CFGKB has exactly the same entries as ECC (Active = T, KB Usage 10, KBOBJNAME and Version filled etc.), but anyhow it is not shown at all in CRM. As these knowledge bases are very huge, I have tested also a very small and easy one. This one is getting downloaded the same way and has the same entries in table COMM_CFGKB and it is also visible in commpr01.
    So my assumption is that the other KBs are not 100% correct. When checking them in ECC (cu36) I get many warnings and errors. Anyhow, they were downloaded to CRM (but won`t be shown). Business says that these warnings/errors are OK and that the external system which uses the IPC in ECC is not having any problems.
    Question: is there any chance of using a KB in CRM which has warning/errors when it was generated in ECC?
    Is there any chance of manipulating the KB before it gets imported into CRM. I have found Note 1044682 which explains a BADI.
    Which tables/fields do we have to manipulate so we are able to use the KB in CRM. 
    As mentioned: business is aware of those errors and excepts that there might be a crash in the IPC for certain combinations.
    Thx
    Guido

    Hi Christophe,
    OK, I think I understand your suggestion: you use the same IPC with your CRM as well as with the ECC system. So in CRM you just maintain the URL and a user in XCM to the "same" IPC. You mentioned that we need to download anyway the SCE. This is somehow logical as this is the base connected to CRM, but what is not clear to me is the fact, that if the SCE KB is used via ECC all SAP R/3 fields are available (like VBTYPE of the sales order where you have values like B or C). In CRM we use the same SCE KB but here these fields are not availble as the sales order transaction customizing in CRM does not contain such a field.  Where is the logical link between the values which are available in IPC and the SCE?
    Thx
    Guido

  • Voice memos sync not shown in iTunes

    I am trying to sync my voice memos to iTunes a couple of times. They are not shown. I haven't updated my iPhone 5s to the latest software yet. It's still running iOS 7; my iTunes was updated though. Does anyone have a solution for this?
    Thank you!!!

    You need to open iTunes on your computer. Then select music library from the left-hand. Then in the search window on the top right of the screen type in voice memo . The voice memo should now appear in the list is available music in the middle of the iTunes screen

  • Yosemite 10.10.1: Finder/CIFS mount problem: wrong folder count/folders not shown @samba shares

    Hello to all,
    we have several MacBook Pro (15" MBP Retina 2012/13"MBP Retina 2014) running. After upgrading to Yosemite 10.10.1 we had one nightmare after the other.
    Most problems could be solved with 3rd party software upgrades but there are several problems with the operating system itselve which can not really  be called a professional productive system at the moment...
    Ok., one thing after the other...here is one of our biggest problems:
    After upgrading from Mavericks or Mountain Lion to Yosemite 10.10.1 the CIFS/SMB mounts to our samba 3.x servers, running on Ubuntu Linux LTS 12.04 makes trouble. We could mount the server shares but after browsing with the Finder the beach ball occures and the Finder hangs forever. Sometimes we could not refresh the Finder, killing the process ended in a complete hang-up of the system which ended in a switch off death blow. This is not amusing because we have 30Tb of customer data there, which has to be worked out.
    We heard about the SMB3 protocol which will be used per default in Yosemite and so we decided after some testings to upgrate our Ubuntu servers to the latest LSF 14.04. release with samba 4.1.6 installed. There was no message from Apple for this SMB protocol release upgrade, never heard something related to Yosemite (Why?).
    Ok, after these server upgrades and disabling most of the Spotlight functions the performance to the CIFS shares was a little bit better as before but now we have another problem with the Finder...if you browse to the shares there are folders missing which have lots of files in it. For example there is a folder with 60 subfolders and 3562 files on the first level in it, the Finder shows 220 files and 15 folders. The Terminal shows a different count with "find . -maxdepth 1 -type d | wc -l" or "find . -maxdepth 1 -type f | wc -l" but there is also a difference to the original file and folder count. It doesn`t matter if the clients are connected via WiFi or Gigabit Ethernet. We have no access problems. We have the same behavior if we set the files and folders to 0777 permissions on the servers. The deletion of the preferences files of the users on the MacBooks does not solve the problem. If we use the "Go To Folder" option and type the path to a folder which is not shown in the Finder you get an result or not. But it is also possible that the result is not correct and there are also still files or subfolders missing.
    In my opinion this is a timeout problem and a "special SMB3 protocol interpretation" which is buggy. We have one hint found in /var/log/system.log:
    "Jan 23 14:35:49 wsosx33.clients.getcom.de KernelEventAgent[69]: tid 54485244 type 'smbfs', mounted on '/Volumes/customersdata2015', from '//x144067:@srvlxp013.servers.getcom.de/customersdata2015', not responding"
    We had no problems with Mavericks at all, we still have no problems with Windows 7 Pro/Ultimate, Windows 2008R2 (native or virtual) or Linux Mint 17/17.1 clients, neither with samba 3.x nor with our actual environment and different newer samba releases.
    We believe that this is a big bug in Yosemite, but we cannot go back to Mavericks because of incompatible TimeCapsule backups. Our workarround at the moment is that we have installed Linux Mint on our MacBooks to get 80% of our daily jobs done, rest has to be done with Windows 7 installed over virtualbox @Linux.
    We have no clue at the moment how to solve this problem, the samba logs do not give any hint. The access from other operating systems is perfect and very fast, but not with Yosemite. We checked different tips found in the internet but nothing helped.
    Does anybody has another idea to get Yosemite working or should we keep Linux Mint until Apple will provide a CIFS/SMB patch and going on with our workaround solution, which is productive at the moment ??? Our staff is not amused and wants one solution and not this workaround with two operating system. We have to decide wether we wait until Apple will get this fixed or we have to switch to Microsoft Windows (which is a No Go for me, but I will not be asked...).
    Thanks in advance
    C.

    Hi William,
    thank you for your response.
    As you can read in my post I talked about CIFS/SMB.
    It makes no difference if we mount the share over CIFS or SMB.
    Folders with lots of files will not be shown even if we use SMB3 or an older protocol.
    As mentioned I believe this is a timeout problem.
    Does anybody know how the CIFS/SMB timeout setting in Yosemite could be changed?
    Kind regards
    C.

  • In my Apple Macbook Air, most of the USB Flash/Thumb Drives are not shown in the Finder Window. Only a few Brands of USB /Flash Thumb Drives are shown or compatible or shown in the Finder. How do I use any Flash/Thumb Drive with my Apple MacAir?

    In my Apple Macbook Air, most of the USB Flash/Thumb Drives are not shown in the Finder Window. Only a few Brands of USB /Flash Thumb Drives are shown or compatible or shown in the Finder. How do I use any Flash/Thumb Drive with my Apple MacAir?

    Yes, junker thumb drives pour like rain in the market.  
    Which makes are working on your Air, and which arent?
    Stick to Sandisk and a couple of other reliable mfg. of memory sticks

  • Reporting tab is not shown in the console

    hi everyone
    the reporting tab is not shown in the service manager console, the topology i am using is 2 servers [one for DW and the other for management server] both servers have their SQL server installed on each one, could you please tell me how i can start to get
    this working or the steps i have to follow ?? isn't supposed to be working out of the box ? i have checked reporting services and they are running

    Probably your report server is not pointing to the DWDATAMART database, try login to:
    http://YourDWDatabase/Reports/Pages/Folder.aspx?ItemPath=%2fSystemCenter%2fServiceManager&ViewMode=List
    click on DWDATAMART Connection, under connection string, do you see your DWDATAMART DB name and server name?
    Antoine AL Ibry

  • Text in PO(text tab in header & item) is not shown in the Print Preview

    Hi Guys,
                I face a problem in ME23N.Text maintained in Purchase Orders (text tab in header & item)  is not shown in the Print Preview.
                Can you guys help.Do I need to write a subroutine pool for this.
                <<text removed by moderator>>
    Regards,
    Rajiv
    Edited by: Matt on Nov 12, 2008 1:20 PM

    Hi ,
    Use bapi bapi_po_getdetail .
    CALL FUNCTION 'BAPI_PO_GETDETAIL'
        EXPORTING
          purchaseorder   = is_ekko-ebeln
          item_texts      = c_x
          header_texts    = c_x
        TABLES
          po_header_texts = it_header_text
          po_item_texts   = it_item_text.
    Regards
    Neetesh

  • Approved and published items are not shown in the catalog search

    Hello all,
    We are implementing SRM 4.0 SSP scenario .
    To support shopping of EBP we are also implementing CCM 2.0 as an add on.
    Please note CCM and EBP are on same client and CAT & CSE are also on the same client.
    No XI is involved. The catalog scheme was uploaded as CSV 2.0. The items for the catalog was created manually in CAT.
    Although the item has the status "approved" and the procurement catalog which is also the master catalog was published successfully the item is not shown after searching by CSE in EBP. Also the categories of the scheme are not shown in the catalog search.
    Do i have to approve the categories too and if yes can you  explain me how to do this?
    I think you see that I'm a newbie at srm and ccm and this problem is probably no real problem but I have not found any similar topics in the forum. So please can you help.
    Thanks a lot for your help.
    Best regards,
    Bernd

    Bernd: the reason I asked about views is that you don't have any error messages. This might indicate that (a) you have no items in the view, or (b) there's something wrong with view-role-user assignment.
    To check for (a), please go to the published procurement catalog, and go to Views tab. Check that your View is Active. Click on your View ID link to display view details. You should see a list of characteristics assigned to your view in Assign Characteristics sub-tab (the list should not be blank!). Go to Assign Items sub-tab. Navigate in your schema to find items that are supposed to be assigned to your view. You should see "Yes" in the "Assigned" column for those products. If you don't, then you simply don't have any items in your view.
    Another thing I'd like you to check: when the user calls your procurement catalog for search, do you see the name of the catalog displayed just below the drop-down "Select Categories Hierarchically"?
    Cheers,
    Serguei

Maybe you are looking for