Custom JTree TreeCellRenderer with JPanel

I have developed a custom TreeCellRenderer which extends JPanel to allow multple icons to be displayed and changed as the context changes. The JPanel has one or two icons and a JLabel which I control based on display context. The renderer works fine with one exception. If the initial string displayed beside the icons is short (such as 4 characters) when I try to display it with a longer string the JPanel does not resize to allow displaying the entire string. I've tried several variation to get the JPanel to resize. I've exanined the code in operation and it seems as though the size of the JLabel is being change correctly and the setPreferredSize on the JPanel is changing correctly. It just wont display without truncating the longer JLabel.
I've reviews the forum to no avail.
The code follows. Any thoughts are appreciated
import javax.swing.ImageIcon;
import java.awt.Image;
import javax.swing.JLabel;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.JTree;
import com.logixpartners.planlogix.insuranceobject.*;
import com.logixpartners.planlogix.utility.RtnObject;
import java.awt.*;
public class PLIconLabel extends javax.swing.JPanel implements TreeCellRenderer {
ImageIcon a,b;
int fWidth = 0;
int sWidth = 0;
String text = "";
JLabel one, two, three;
InsObject io;
boolean selected;
FontMetrics fontMetrics;
int iconHeightPad = 0;
int fontH, fontLen, iconH = 30+iconHeightPad;
/** Creates a new instance of PLIconLabel */
public PLIconLabel() {
super(null); //null indicates no layour manager
one = new JLabel();
one.setIconTextGap(0);
two = new JLabel();
two.setIconTextGap(0);
three = new JLabel();
three.setIconTextGap(0);
add(one);
add(two);
add(three);
public void setIconOne(ImageIcon i) {
a = i;
fWidth = a.getImage().getWidth(this);
one.setBounds(0,0, fWidth, a.getImage().getHeight(this)+iconHeightPad);
if (b != null) {
two.setBounds(fWidth,0,sWidth,b.getImage().getHeight(this)+iconHeightPad);
three.setBounds(fWidth+sWidth+5,0,fontLen, iconH);
one.setIcon(a);
repaint();
public void removeIconOne() {
a = null;
fWidth = 0;
if (b != null) {
two.setBounds(fWidth,0,sWidth,b.getImage().getHeight(this)+4);
three.setBounds(fWidth+sWidth+5,0, fontLen, iconH);
one.setIcon(a);
repaint();
public void setIconTwo(ImageIcon i) {
b = i;
sWidth = b.getImage().getWidth(this);
two.setBounds(fWidth,0,sWidth,b.getImage().getHeight(this)+iconHeightPad);
three.setBounds(fWidth+sWidth+5,0, fontLen, iconH);
two.setIcon(b);
repaint();
public void removeIconTwo() {
b = null;
sWidth = 0;
two.setIcon(b);
two.setBounds(fWidth,0,0,0);
three.setBounds(fWidth+sWidth+5,0,fontLen, iconH);
repaint();
public void setPLText(String t) {
text = t;
three.setText(t);
fontMetrics = three.getFontMetrics(three.getFont());
fontLen = fontMetrics.stringWidth(t);
fontH = fontMetrics.getHeight();
three.setBounds(fWidth+sWidth+5,0,
fontLen+10,
fontH);
repaint();
public java.awt.Component getTreeCellRendererComponent(JTree tree,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {       
try {
io = (InsObject)value;
} catch (java.lang.ClassCastException e) {
e = e;
setPLText(io.getBestName());
if (io.getTypeOf().equals("Ref")){
setPLText(io.getAttribute("Name"));
// Setup colors for node selection
if (sel) {
setBackground(new java.awt.Color(64,128,128));
} else {
setBackground(new java.awt.Color(95,167,152));
// Change text color of node
three.setForeground(sel ? java.awt.Color.white : java.awt.Color.black);
// Get proper Icon for Node
if ((io.getClass().getName()).equals("com.logixpartners.planlogix.insuranceobject.InsObjectRef")){
setIconTwo( (ImageIcon)((RtnObject)PLIcons.getIcon((String)io.getTypeOf())).getReturnValue());
setIconOne((ImageIcon)PLIcons.get("RefPtr") );
} else {
removeIconOne();
if (!expanded && !leaf) {
setIconTwo( (ImageIcon)((RtnObject)PLIcons.getIconX((String)io.getTypeOf())).getReturnValue());
} else {
setIconTwo( (ImageIcon)((RtnObject)PLIcons.getIcon((String)io.getTypeOf())).getReturnValue());
two.setToolTipText((String)io.getTypeOf());
selected = sel;
Dimension dim = new Dimension(three.getWidth()+60+fWidth+sWidth+20,iconH);
setPreferredSize(dim);
setMinimumSize(dim );
setMaximumSize(dim );
setSize(dim);
validate();
return this;
}// end of class

Addition to my original post. I found a forum post noting a similar problem. The suggest fix was to set the JTree row heigth to 0 (zero) and to add a getPreferredSize in the TreeCellRenderer, which gets called when row height is zero, and explicitly set the desired size. This works but with an exception. It seems as though the getPreferredSize is only called once when it is a leaf node being rendered. This seems to be true for expand, collaspe, and select.

Similar Messages

  • How to get my custom controller updated with the global custom controller?

    Hi all,
    I'm new to CRM Web UI and need some advice from the expert. Currently I'm working on component ICCMP_BT_DATES and noticed something weird with this component. When this component is first launch it display the dates of a service ticket correctly. However when I navigate to another screen, save a new ticket and back, the dates are not reflected. When I went in and debug the component, I noticed that the context is still tied to the previous ticket. I think the custom controller is not updated with the latest from the global custom controller.
    My question is how do I get my custom controller updated with the latest.
    Regards,
    Ricky

    You have to bind your custom controllers context node to the event NEW_FOCUS of the collection wrapper on the global custom controller.
    Best place to do this might be the CONNECT_NODES of the context of your custom controller.
    Get the global CuCo with GET_CUSTOM_CONTROLLER() and then the appropriate context node. Now:
    SET HANDLER yourMethod for lr_global_cuco->typed_context->thecontextnode->collection_wrapper activation iv_activate.
    Of course you have to implement a method similar to ON_NEW_FOCUS as it is on many other nodes.
    cheers Carsten

  • Windows Phone - Cannot bind custom user controll with listview item source property

    It is Windows Phone 8.1 (runtime)
    I have some problem of binding custom user controll with list of data. I'll make it simple as I can.
    My problem is that somehow if I use DataBind {Binding Something} inside my custom controll it will not work.
    I need to transfer binded data (string) to custom controll.
    It is strange that if I do not use DataBind, it will work normally. Eg MyCustomControllParameter = "some string" (in my example 'BindingTextValue' property)
    Does anyone Know how to bind custom user controll with inside ListView with DataTemplate.
    Assume this:
    XAML Test-Main page
    <Grid  Background="Black">        <ListView x:Name="TestList" Background="#FFEAEAEA">                    <ListView.ItemTemplate>                <DataTemplate>                    <Grid Background="#FF727272">                        <local:TextBoxS BindingTextValue="{Binding Tag, FallbackValue='aSource'}" local:TextBoxS>                    </Grid>                </DataTemplate>            </ListView.ItemTemplate>        </ListView>    </Grid>
    XAML Test-Main page c#
    public sealed partial class MainPage : Page    {        List<TTag> tags = new List<TTag>();        public MainPage()        {            this.InitializeComponent();            this.NavigationCacheMode = NavigationCacheMode.Required;        }        public class TTag        {            public string Tag { get; set; }        }        private void InitializeAppData()        {            TTag tag = new TTag() { Tag = "hello world" };            tags.Add(tag);            tags.Add(tag);            tags.Add(tag);            TestList.ItemsSource = tags;        }             protected override void OnNavigatedTo(NavigationEventArgs e)        {            InitializeAppData();        }           }
    User Control XAML:
      <UserControl    x:Class="CustomControllTest.TextBoxS"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:local="using:CustomControllTest"    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    mc:Ignorable="d"    d:DesignHeight="300"    d:DesignWidth="400">      <Grid x:Name="LayoutRoot" Background="#FF4F4F4F"   >        <RichTextBlock x:Name="MyTestBlock">        </RichTextBlock>    </Grid></UserControl>
    User Control c#
    public TextBoxS()       {            this.InitializeComponent();            LayoutRoot.DataContext = this;        }        public static readonly DependencyProperty BindingTextValueProperty = DependencyProperty.Register(                                         "BindingTextValue",                                         typeof(string),                                         typeof(TextBoxS),                                         new PropertyMetadata(default(string)));        public string BindingTextValue        {            get            {                return GetValue(BindingTextValueProperty) as string;            }            set            {                SetValue(BindingTextValueProperty, value);                //This method adds some custom logic into RichTextBlock, pointed correctly                SetupBox(value);            }        }
    Thanks for helping ;)

    If you use a built-in control rather than your custom control, does binding work? You should verify that first.
    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.
    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined
    objects and unknown namespaces.

  • Problem with Jpanel repaintingl

    Hi!
    I have a problem with Jpanel.
    First , I add a Jscrollpane to the panel and I don't
    see it.
    Second, I have a paint method in the Jpanel and I do there some painting but when I exe the application I can see the panel painting only when I put the mouse cursor
    on the place where the panel need to be.
    It is very strange.
    Help me.
    Yair.

    Example code??
    Can't tell what's wrong otherwise.
    First , I add a Jscrollpane to the panel and I don't
    see it.Have you added anything to this JScrollPane? Unless you set the scroll bar policies to always on you won't see anything if you haven't added anything to the scrollpane.
    Also, if you're only adding this scrollPane to your JPanel initilise it with
    JPanel whippet = new JPanel(new BorderLayout())
    .. then when you add your scrollPanel to your JPanel do this to make sure its added slap in the in middle of it:
    whippet.add(yourScrollPanel, BorderLayout.CENTER);
    Bit more info please - duuuuuuuuuuuuuuuude (man, "Finding Nemo" was well funny didn't you think.. anyways, that's besides the point.... could just be my 8 year old mental age though.. who knows.)?

  • Customer line items with balance carry forward no opening balance

    Hello FI Experts,
    We have ticket where the user is using a Z* Report for Customer line items with balance carry forward. In 31.01.2007 user has posted some legacy data, latter he was executing this Z* report then user can see the values posted on the same day (31.01.2007) as line items. But he was executing the report on 01.02.2007 then he was not able to see the line item as well as the values posted on 31.01.2007 as opening balance as on 01.02.2007. But if we run the report as on 01.01.2008 then we are able to see the values which are carry forwarded as opening balances. Did anyone have worked on this type of scenario?
    Requirement Here Is:  The values that have been posted on 31.03.2007 which are still open line items should get displayed as opening balance as on 01.02.2007.
    Thanks for helping on this issue.

    Hi,
      Any report will get data from Tables. Please check whether the table you have used to develop this report has opening balance.
    Balance will be carry forwarded only when you run the balance carry forward program. Check whether this was run for the date you have specified. This can be done in the year end.
    If you are checking in the middle of the year, then the balance will not be carry forwarded.
    Regards,
    B. Radhika.

  • Custom report templates with the help of BI Publisher.

    Hi All,
    I have created custom report templates with the help of BI Publisher it is working as we excepted.
    refered : https://blogs.oracle.com/kyle/tags/reports
    But our requirement want to change the color of heading and include filters in output report, It is possible, if yes pls share you comments?
    Best Regards
    Pradeep

    how silly of me!
    just restarting the tomcat sorted the problem!!!

  • VENDOR/GL/CUSTOMER  ACCOUNT STATEMENT WITH OPENING BALANCE

    Can anybody  tell me the tcodes in SAP for Vendor/Gl/Customer Account Statement with opening balance.
    Best Regards,
    Sudhanshu Dang
    0124-3081015

    hii
    As per my knowledge no such reports  for GL are there in sap.. we also had a same requirement but could not find it... we wanted reports with opening and closing balalnces...
    u can go to SAP1 and check all the standard reports available. check wheather any report fulfills ur need or else go for abap reports...
    Check f.42 T code for Vendor Report. and s_alr_87012172..for customer.
    thanks
    sejal

  • How to create a custom function module with the records in SAP R/3?

    Hi All,
    How to create a custom function module with the records in SAP R/3? Using RFC Adapter I have to fetch the custom function module records.
    Regards
    Sara

    Hi
    goto se37...here u need to create a function group... then u need to create a function module. inside assign import/export parameters. assign tables/exceptions. activate the same. now write ur code within the function module
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/db98fc35c111d1829f0000e829fbfe/content.htm
    Look at the below SAP HELP links, These links will show you the way to create a Function Module
    http://help.sap.com/saphelp_nw04/helpdata/en/26/64f623fa8911d386e70000e82011b8/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/db98fc35c111d1829f0000e829fbfe/content.htm

  • Data not storing in Custom infotype build with tab strips

    Hi All,
    I have created one custom infotype 9030,
    With screen 2000.
    which is having tab strips, I have build the screens refering to p9030-zztest its not storing in database.
    where I am doing wrong...please let me know what should be done in this case.
    Regards
    Satish.v

    Hi,
    Checkout the below link :
    <link to blacklisted site removed by moderator>
    Shailaja Ainala.
    Edited by: Thomas Zloch on Jan 28, 2012 9:06 PM

  • Photosmart C410: How do I associate a custom paper size with the photo tray?

    Our Photosmart 3310 recently broke down and I purchased a C410 to replace it.  I sell a small item online that I ship in 3 5/8 x 6 1/2 envelopes.  With the 3310, I had figured out a way to print the envelopes from the photo tray.  While Word 2007 allows me to select the photo tray, the printer would not print from there until I created a custom paper size in the printer preferences dialog box.
    One of the reasons I got the C410 was for the photo tray.  It's a real pain to have to swap out the regular paper and stick in one evelope every time I want to print another envelope.  Well, unfortunately, that's what I've been doing.  I select the photo tray in Word, but the printer goes right ahead and prints from the main tray.  I had forgotten what I did to make it work on the 3310, so I experimented with that printer's drivers until I figured it out.
    My problem is that the software interface for the C410 is different than that for the 3310.  I can't figure out how to associate a custom paper size with the photo tray.  To test my theory this evening, I told Word that my envelope size was 5 x 7.  The printer didn't hesitate to take an envelope from the photo tray.  Of course the return address went into a dark void because the envelope is not 5 x 7.
    The difference between the two interfaces is that the 3310 has both printing shortcuts as well as "Print Task Quick Sets."  The C410 only has printing shortcuts.
    If anyone can help me, I'll be very grateful!  I've probably spent hours trying to get this figured out, and I have no idea what to do.

    Hi,
    Which Microsoft product (application) are you using ? Printer supports the following custom sizes:
    From ADF: Custom-sized media (ADF) between 127 to 216 mm wide and 241 to 305 mm long (5 to 8.5 inches wide and 9.5 to 12 inches long)
    From input tray: Custom-sized media between 76.2 to 216 mm wide and 101 to 762 mm long (3 to 8.5 inches wide and 4 to 30 inches long)
    You need to select right custom size from the application.
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • Adding Custom Breadcrumb for SharePoint 2013 Custom Master-Page With A Custom Separator.

    Hi All,
    I have successfully converted an HTML file to a SharePoint 2013 Custom Master-Page with relevant style sheets. But when I used within the SharePoint site I could not find the breadcrumb. So I want to know how to do that? For that breadcrumb I need a custom
    separator like an arrow like in the below.
    As you can see the separator is a custom built one. To have this custom separator in my HTML I have used the following code snippet.
    <div class="breadcrumb-desktop">
    <span class="breadcrumb-links"><a href="#">SharePoint Site Home</a></span>
    <span class="breadcrumb-links"><a href="#">Sub Link 01</a></span> Active Page
    </div>
    The styles are as like in the below.
    .breadcrumb-desktop {
    width: 100%;
    font-family: Arial;
    padding: 23px 0 40px;
    float: left;
    font-size: 0.75em;
    line-height: 1.25;
    .breadcrumb-desktop > span.breadcrumb-links:after {
    content: " \203A ";
    white-space: pre;
    I have tried the following code snippet within the SharePoint site as
    <!--MS:<asp:sitemappath runat="server" sitemapproviders="SPSiteMapProvider,SPXmlContentMapProvider" rendercurrentnodeaslink="false" hideinteriorrootnodes="true">-->
    <!--ME:</asp:sitemappath>-->
    But it did not display as I wanted.
    So how am I supposed to insert these to my Custom Master-Page's breadcrumb and style them? Please could someone help me to solve this?
    Thanks and regards,
    Chiranthaka

    Hi Chiranthaka,
    Please use the following code snippet in your html master page.
    <div class="CustomBreadcrumbs">
    You are here:
    <!--SPM:<SharePoint:AjaxDelta id="DeltaPlaceHolderPageTitleInTitleArea" runat="server">-->
    <!--SPM:<asp:ContentPlaceHolder id="PlaceHolderTitleBreadcrumb" runat="server">-->
    <!--MS:<asp:sitemappath runat="server" sitemapproviders="SPSiteMapProvider,SPXmlContentMapProvider" rendercurrentnodeaslink="false" hideinteriorrootnodes="true">-->
    <!--ME:</asp:sitemappath>-->
    <!--SPM:</asp:ContentPlaceHolder>-->
    <!--SPM:</SharePoint:AjaxDelta>-->
    </div>
    Here is a thread for your reference:
    https://social.msdn.microsoft.com/Forums/office/en-US/daabd903-df98-41da-80d8-6a942d06980e/add-breadcrumb-to-custom-master-page-html-file?forum=sharepointcustomization
    We can also customize a breadcrumb control, then add it in master page.
    http://msreddysharepoint.blogspot.com/2013/01/custom-breadcrumb-navigation-in.html
    Best Regards
    Dennis Guo
    TechNet Community Support

  • Refreshing the jtree in a jpanel

    hi,
    i created a jtree of files in a certain folder... if some files changed in my folder, how can i refresh the jtree in my jpanel...
    thanks!!!

    Hi,
    look here:
    http://forum.java.sun.com/thread.jspa?threadID=478780&messageID=2226565
    L.P.

  • Creation of a simple custom fact sheet with assignment block

    Dear CRM Gurus,
    i need to create a custom fact sheet with a assignment block and link for that has to be given in a navigation bar . once if I click on  that navigation bar the custom fact sheet has to be displayed. am relatively very new to crm. kindly help me in this aspect.

    Hi Thomas,
    " By default, the Collect Signatures workflow is associated with the Document content type and it is thus automatically available in document libraries for documents or workbooks that contain Microsoft Office Signature Lines. "
    It doesn't work for a custom list which cannot be added with the document content type, please see more information from below,
    http://office.microsoft.com/en-us/sharepoint-server-help/use-a-collect-signatures-workflow-HA010154428.aspx
    Thanks
    Daniel Yang
    TechNet Community Support

  • Facing Problem in creation on Customer Master Record with reference

    Dear SAP Experts,
    I am making a New Customer master record with referenec to existing one. Account  Group """ Stock Transfer - Depot""" do not use internal no assignment, we put external no to customer code. but when we enter the customer master with reference to existing one, system shows the error.....enter a no between A001 and Z999.
    Customer Record Details-
    Account Group - Stock Transfer Depot
    Customer - 1101
    Compnay Code- 1000
    Sales Organisation - 1000
    Distribution Channel -20
    Division - 01
    Reference:
    Customer - 2001
    Comapny Code - 2000
    Sales Organisation - 2000
    Distribution Channel - 20
    Division - 01
    Error: ENTER A NO BETWEEN  A001 AND Z999
    I m not getting why system showing this type of error, should i need to configure new customer code sumwhere in IMG if yes please let me know.
    Lokking forward for your quick response on the same.
    Regards
    Parul Deshwal

    Hi Parul Deshwal,
    - The number range is created in XDN1.
    - The number range is assigned to the account group "Stock Transfer - Depot" in SAP Customizing Implementation Guide>Financial Accounting>Accounts Receivable and Accounts Payable>Customer Accounts>Master Data>Preparations for Creating Customer Master Data>Assign Number Ranges to Customer Account Groups
    Remember - If you are entering an external number it generally means the number is created in an external system and replicated to your system.
    Help - Check what external number was used last by doing SE16 on table KNA1 and use the account group "Stock Transfer - Depot" as a selection parameter.
    Best regards,
    Glynn

  • Adobe InDesign CC 2014 Custom Panel Built With Extension Builder - Problem: Can't tab from one entry field to the next; Hitting tab instead hides all palettes; Is there a fix? This didn't happen in Adobe Indesign CC

    Adobe InDesign CC 2014 Custom Panel Built With Extension Builder - Problem: Can't tab from one entry field to the next; Hitting tab instead hides all palettes; Is there a fix? This didn't happen in Adobe Indesign CC

    This is planned to be fixed in the next release.

Maybe you are looking for