How to remove a cell renderer

I have been looking through the apis and search but to no sucess. I have tried a few different remove methods but none seem to be working. Does anyone know how to remove a cell renderer.

What do you mean "remove a cell renderer".
What component or class are you talking about? I'm only aware of renderers being used by Swing components. If thats the case then the question should be posted in the Swing forum.
What do you mean by remove? If you remove the renderer how would the cell be renderered. Do you mean that you want the cell to use the default cell renderer?
What component are you talking about? I'm aware of renderers for JTree, JTable, JList, JComboBox.
If I had to guess I would think you are talking about a JTable, so I would suggest simple setting the renderer to null for the particular column.
If that doesn't work then you can always use the getDefaultRenderer(...) method and then reset the column that way?
But you question is not very clear so Its a lot of guess work on my part.

Similar Messages

  • How to set table cell renderer in a specific cell?

    how to set table cell renderer in a specific cell?
    i want set a cell to be a button in renderer!
    how to do?
    any link or document can read>?
    thx!

    Take a look at :
    http://www2.gol.com/users/tame/swing/examples/SwingExamples.html
    It is very interesting, and I think your answer is here.
    Denis

  • How to make JTree cell renderer respect layout?

    Hi,
    In the JTree tutorial, the first example TreeDemo shows a simple tree.
    http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html
    If you grab the frame and make it really thin, you get a horizontal scroll bar in the top pane.
    How can I make it so that the tree cells just draw "..." at the end of the string if there is not enough space?
    I know the tree cell renderer uses JLabel, but they never seem to show "...", which is one of the best features of a JLabel. Any help is greatly appreciated!

    Hi,
    I got it working, but I also discovered a Java bug that ruins all this effort!
    Calculating the node's position & width:
    - When child nodes are indented, there is an "L" shaped line drawn... the space to the left of the line's vertical bar is the "leftChildIndent", and the space to the right is the "rightChildIndent". So you add both to get the whole indent.
    - I use label.getPreferredSize().width to figure out the node width, since that includes the icon width, the icon-text gap, and the font metrics.
    Example program:
    - This program models how I want it to look... Always expanded and automatic "..." when the scroll pane is not big enough.
    Bug found:
    - There is a runnable example below. Just run it and after a couple seconds, move the split pane to the right.
    - I use a timer to add a new node every 1 second. The new nodes get stuck being too small, and the original nodes don't have this problem.
    // =====================================================
    * Adaptation of TreeDemo to allow for tree nodes that show "..."
    * when there is not enough space to display the whole label.
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JSplitPane;
    import javax.swing.JTree;
    import javax.swing.Timer;
    import javax.swing.UIManager;
    import javax.swing.event.TreeExpansionEvent;
    import javax.swing.event.TreeWillExpandListener;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeCellRenderer;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.ExpandVetoException;
    import javax.swing.tree.TreeCellRenderer;
    import javax.swing.tree.TreeSelectionModel;
    public class TreeDemo extends JPanel {
        private JTree tree;
        protected class EllipsesTreeCellRenderer implements TreeCellRenderer {
            Integer leftIndent = (Integer) UIManager.get("Tree.leftChildIndent");
            Integer rightIndent = (Integer) UIManager.get("Tree.rightChildIndent");
            int indent = leftIndent.intValue() + rightIndent.intValue();
            JLabel label = new JLabel();
            DefaultTreeCellRenderer r = new DefaultTreeCellRenderer();
            public Component getTreeCellRendererComponent(JTree tree, Object value,
                    boolean selected, boolean expanded, boolean leaf, int row,
                    boolean hasFocus) {
                label.setText("why hello there why hello there why hello there");
                if (selected) {
                    label.setForeground(r.getTextSelectionColor());
                    label.setBackground(r.getBackgroundSelectionColor());
                } else {
                    label.setForeground(r.getTextNonSelectionColor());
                    label.setBackground(r.getBackgroundNonSelectionColor());
                if (leaf) {
                    label.setIcon(r.getLeafIcon());
                } else if (expanded) {
                    label.setIcon(r.getOpenIcon());
                } else {
                    label.setIcon(r.getClosedIcon());
                label.setComponentOrientation(tree.getComponentOrientation());
                int labelWidth = label.getPreferredSize().width;
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
                int level = node.getLevel();
                if (!tree.isRootVisible()) {
                    --level;
                int indentWidth = indent * level;
                int rendererWidth = labelWidth + indentWidth;
                // This is zero the first few times getTreeCellRenderer is called
                // because the tree is not yet visible.
                int maxWidth = (int) tree.getVisibleRect().getWidth();
                if (maxWidth > 0) {
                    if (rendererWidth > maxWidth) {
                        // figure out how much space "..." will consume.
                        label.setText(label.getText() + "...");
                        maxWidth = maxWidth
                                - (label.getPreferredSize().width - labelWidth);
                        label.setText(label.getText());
                        // chop off characters until "..." fits in the visible
                        // portion.
                        if (maxWidth > 0) {
                            while (rendererWidth > maxWidth
                                    && label.getText().length() > 1) {
                                label.setText(label.getText().substring(0,
                                        label.getText().length() - 2));
                                rendererWidth = indentWidth
                                        + label.getPreferredSize().width;
                            label.setText(label.getText() + "...");
                return label;
        public TreeDemo() {
            super(new GridLayout(1, 0));
            //Create the nodes.
            final DefaultMutableTreeNode top = new DefaultMutableTreeNode("");
            createNodes(top);
            //Create a tree that allows one selection at a time.
            tree = new JTree(top);
            tree.getSelectionModel().setSelectionMode(
                    TreeSelectionModel.SINGLE_TREE_SELECTION);
            tree.setCellRenderer(new EllipsesTreeCellRenderer());
            tree.addTreeWillExpandListener(new TreeWillExpandListener() {
                public void treeWillExpand(TreeExpansionEvent event) {
                public void treeWillCollapse(TreeExpansionEvent event)
                        throws ExpandVetoException {
                    throw new ExpandVetoException(event);
            for (int i = tree.getRowCount(); i >= 0; i--) {
                tree.expandRow(i);
            //Create the scroll pane and add the tree to it.
            JScrollPane treeView = new JScrollPane(tree);
            //Add the scroll panes to a split pane.
            JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
            splitPane.setTopComponent(treeView);
            splitPane.setBottomComponent(new JLabel(""));
            Dimension minimumSize = new Dimension(0, 0);
            treeView.setMinimumSize(minimumSize);
            splitPane.setDividerLocation(200); //XXX: ignored in some releases
            //of Swing. bug 4101306
            //workaround for bug 4101306:
            //treeView.setPreferredSize(new Dimension(100, 100));
            // Makes tree nodes appear cut-off initially.
            splitPane.setPreferredSize(new Dimension(500, 300));
            //Add the split pane to this panel.
            add(splitPane);
            // Adds a new node every 1 second
            Timer timer = new Timer(1000, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
                    DefaultMutableTreeNode child = new DefaultMutableTreeNode("");
                    model.insertNodeInto(child, top, 0);
                    for (int i = tree.getRowCount(); i >= 0; i--) {
                        tree.expandRow(i);
            timer.start();
        private void createNodes(DefaultMutableTreeNode top) {
            DefaultMutableTreeNode category = null;
            DefaultMutableTreeNode book = null;
            category = new DefaultMutableTreeNode("");
            top.add(category);
            category.add(new DefaultMutableTreeNode(""));
            category.add(new DefaultMutableTreeNode(""));
            category.add(new DefaultMutableTreeNode(""));
            category.add(new DefaultMutableTreeNode(""));
            category.add(new DefaultMutableTreeNode(""));
            category.add(new DefaultMutableTreeNode(""));
            category.add(new DefaultMutableTreeNode(""));
            category.add(new DefaultMutableTreeNode(""));
            category.add(new DefaultMutableTreeNode(""));
         * Create the GUI and show it. For thread safety, this method should be
         * invoked from the event-dispatching thread.
        private static void createAndShowGUI() {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (Exception e) {
                System.err.println("Couldn't use system look and feel.");
            //Make sure we have nice window decorations.
            JFrame.setDefaultLookAndFeelDecorated(true);
            //Create and set up the window.
            JFrame frame = new JFrame("TreeDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Create and set up the content pane.
            TreeDemo newContentPane = new TreeDemo();
            newContentPane.setOpaque(true); //content panes must be opaque
            frame.setContentPane(newContentPane);
            //Display the window.
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }

  • How to remove table cell borders

    Hi,
    I’m using dreamweaver cs6.first i create a HTML page then i create a div tag (800w 900 h) & create a table inside of above div. i want to keep table border & make it to tickness, want to remove cell borders. I can’t find any options to remove the cell borders. Please any one can help me.
    Thank you.

    table.borderless {
    border-width: 0px;
    background-color: white;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-weight: bold;
    font-size: 1.2em;
    text-align: center;
    text-transform: none;
    table.borderless th {
        border-width: 0px;
        padding: 5px;
        background-color: white;   
    table.borderless td {
        border-width: 0px;
        padding: 5px;
        background-color: white;
    <table width="250" height="150" align="center" class="borderless">
    <tr>
      <th colspan="2" class="style1">Borderless table<br />
       cell 1 &amp; 2 merged</span> </th>
      </tr>
    <tr>
      <th class="borderless">cell 3 </th>
      <td class="borderless">cell 4 </td>
    </tr>
    <tr>
        <th>cell 5 </th>
        <td>cell 6 </td>
    </tr>
    </table>

  • How to remove an item renderer

    Hi,
    I am applying itemrenderer for in the columnseries of column
    chart
    cs.setStyle("itemRenderer",new
    ClassFactory(CycleColorRenderer1));
    At a particular condition i need to remove this
    itemrenderer.Hw can i achive this?Any one pls respond.

    "san00001" <[email protected]> wrote in
    message
    news:gh7r4m$88j$[email protected]..
    > Hi,
    > I am applying itemrenderer for in the columnseries of
    column chart
    >
    > cs.setStyle("itemRenderer",new
    ClassFactory(CycleColorRenderer1));
    >
    > At a particular condition i need to remove this
    itemrenderer.Hw can i
    > achive
    > this?Any one pls respond.
    Did you try
    cs.setStyle("itemRenderer", null)

  • How to remove cells interection line in JTable

    Hello
    I am new to Java Programming
    I am facing a problem which i did not know how to solve so i need help from experts of this forum
    I have JTable of lets say 5 columns and from that i want to hide some columsn e.g i want to get only column 0(or ist column) and column 5(5th column) visible to me and not the inbetween columns(i.e 2,3,4) so i coded it like this:
    for(int count=0;count< ConnectedDrivestable.getColumnCount();count++)
                   tcm = ConnectedDrivestable.getColumnModel();
                   cm=tcm.getColumn(count);
                  if( count==0 || count==4)
                       cm.setPreferredWidth(15);
                   cm.setMinWidth(0);                   
                       cm.setMaxWidth(15);                   
                  else {
                       //ConnectedDrivestable.removeColumn(cm);
                           //ConnectedDrivestable.removeColumn(tcm.getColumn(count));
                       cm.setPreferredWidth(0);
                   cm.setMinWidth(0);          
                       cm.setMaxWidth(0);
              }where ConnectedDrivestable is my JTable of lets say 5 rows and 5 columns
    tcm is TableColumnModel and cm is TableColumn object
    But the problem is that i am getting vertical line in between and that is the intersection line of column 1 and column 5(i.e the intersection line of two columns that are visible) i dont want this in between vertical line to appear
    I really dont know how to fix this problem i have searched on internet but unable to find the appropriate solution to it
    Also as shown in my code i tried to work with removeColumn method which documentation says should remove the desired columns but i dont know why it is not functioing for my case the way i acpected am i doing something wrong or?
    So urgent help from people here is required
    Thanks in advance
    Imran

    Hello
    Thanks for reply and thanks for help
    Do please tell me that i am rendering cells of JTable with JLabel it is working fine but i want to span JLabel onto multicells in the same row
    Second i want to change the size of JLabel so that if not needed JLabel did not cover the whole Cell
    A bit of code which i am using to do cel rendering is attched for your kind considerations
    ConnectedDrivestable.getColumnModel().getColumn(1).setCellRenderer((new  DefaultTableCellRenderer ()
                   public Component getTableCellRendererComponent(JTable table, Object value,
                             boolean isSelected,
                             boolean hasFocus,
                             int row, int column)
                        JLabel Jlbl=new JLabel();
                        if(row==2)
                             ((JComponent)Jlbl).setOpaque(true); //if comp is a JLabel:Necessary
                             //Jlbl.setBorder(BorderFactory.createLineBorder(Color.BLACK));
                             Jlbl.setBackground(Color.GREEN);
                             Jlbl.setLocation(row,column);
                             System.out.print("The Column number is : "+column);
                             System.out.print("The answer is: "+ column+2);
                             ((JComponent)Jlbl).setMinimumSize(new Dimension(1,1));
                             ((JComponent)Jlbl).setMaximumSize(new Dimension(0,0));
                        return Jlbl;
                        //return comp;
              }));Another piece of code which i got from internet for doing the same is
    ConnectedDrivestable.getColumnModel().getColumn(2).setCellRenderer((new  DefaultTableCellRenderer ()
                   public Component getTableCellRendererComponent(JTable table, Object value,
                             boolean isSelected,
                             boolean hasFocus,
                             int row, int column)
                        Component comp = super.getTableCellRendererComponent
                             (table, value, isSelected, hasFocus, row, column);                         
                        //((JComponent)comp).setBorder(new LineBorder(Color.BLACK));                         
                        if(row==2 && column==2)
                             //((JComponent)comp).setBorder(new LineBorder(Color.BLACK));
                             comp.setBackground(Color.GREEN);
                             ((JComponent)comp).setMinimumSize(new Dimension(1,1));
                             ((JComponent)comp).setMaximumSize(new Dimension(1,1));                                   
                        else
                             comp.setBackground(Color.white);
                        return comp;
              }));These both work but as i tried to change the size of JLabel in the Cells it did not work also if i wanted to span JLabels to multiple cells(Column) is it not working
    Also as in code snippet i am trying to set the border which works fine but what i want is that after spanning JLabel to multiple cells then i want border along this how to do this help in this regard too?might if i could span JLabel to diffrent columns might i able to set border aroung them too
    I am putting under old forum topic this question as it is realted to my same problem so do please apologize me.
    I do need urgent help in this regard so kind help is needed
    Regards

  • How to remove the "0" from the sum cell when the other cells are empty?

    Hello!
    When I use the formula to sum the values from a few cells, there is a zero in the sum cell when the other cells are empty.
    My question concerns how to remove the 0 from the sum cell when the cells that will be summed are empty.
    Thank you!
    /Johan Strömbeck

    Hi,
    Please try the Mr. Laurence's suggestion first. Then, we may try the other workarounds.
    1) Go to Excel option> Advanced>Display Option for this worksheet> Uncheck Show a zero in cells that have zero value
    2) Go to Conditional Formatting>New Rule>Format only cells that contain> Value equal to 0> Format the color with white
    Hope it's helpful.
    Regards,
    George Zhao
    TechNet Community Support

  • I purchased iphone4s recently and in phone section my cell number is showing unkmown and down there its showing vf es services why and how to remove ?

    i purchase recently iphone 4s and its not showing my cell number and further down there its appearing SIM PIN AREA  vf es services
    could any one can help me how to remove this carrier  vf es services ?
    also i think due to this my cell's roaming data is on then only internet is working.....

    Open contacts list, favourites should be at the top of list with stars by them, select  the one you want to unfavourite, long hold and a pop up menu gives you the options to call-send message-Remove from favourites_send as contact card-Delete-or Mark. Chose the option to remove from favourites and they won't show on home screen any more !
    If I have helped at all, a click on the White Star is always appreciated :
    you can also help others by marking 'accept as solution' 

  • TableSorter + custom cell renderer: how to get DISPLAYED value?

    Hi!
    I have a JTable with a custom cell renderer. This renderer translates numerical codes, which are stored in the table model, into textual names. E.g. the table model stores country codes, the renderer displays the name of the country.
    Now, having a reference on the JTable, how can I get the DISPLAYED value, i.e. the country name? Is there some method like ....getRenderer().getText()?
    Thanx,
    Thilo

    Well, a renderer can be anything. It may be rendering an image not text so you can't assume a method like getText(). However, since you know the component being used to render the cell you should be able to do something like:
    TableCellRenderer renderer = table.getCellRenderer(row, column);
    Component component = table.prepareRenderer(renderer, row, column);
    Now you can cast the component and use get text.
    Another option would be to store a custom class on the table cell. This class would contain both the code and value. The toString() method would return the value. Whenever you want the code you would use the table.getValueAt(...) method and then use the classes getCode() method. Using this approach you would not need a custom renderer. This thread shows how you can use this approach using a JComboBox, but the concept is the same for JTable as well:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=417832

  • How to remove all columns and cells in numbers

    how to remove all columns and cells in numbers

    Click on the Table's icon in the Sheets list. Press delete.
    Done.
    Regards,
    Barry

  • How to remove Cross Marks in the Report Column.of Cell..!!

    Hi Experts,
    I am facing an issue. I have included a Formula in the Cell  at Query Level.
    When i run the report in the Bex Analyzer.
    for that Formula column in the report there is some Cross Marks with Red Colour is displaying.
    But the Formula is added in the Cell area at Query designer level.
    Here user requirement is if there is no values calculated in the Formula column there should be no values has to be displayed.
    But unfortunately, here i am getting Cross Marks or Mulitply Symbol is displaying.
    My Question is Pls advice, How to remove those Red Cross Marks in the report of that Column.
    Thanks,
    SN.

    Hi,
    Whenever there is no value, by default, and SAP standard, it shows X mark.
    At reporting level you cannot do changes, as this change has to be done at global level. Hence make sure that if this has to be changes this will affect other reports too.
    If you still feel that X mark has to be displayed as blank, then you can do this in SPRO settings.
    SPRO->Display IMG->SAP Netweaver->Business Intelligence->Settings for Reporting and Analysis->and execute Presenting the numeric value in the Bex.
    Change the value:
    Does not exist : Remove X.
    Hope this solves your issue.
    Regards
    Jeeth

  • How to remove special characters while typing data in edit cell in datagrid in flex4

    Hi Friends,
    I am facing this problem "how to remove special characters while typing data in edit cell in datagrid in flex4".If know anyone please help in this
    Thanks,
    Anderson.

    Removes any characters from
    @myString that do not meet the
    provided criteria.
    CREATE FUNCTION dbo.GetCharacters(@myString varchar(500), @validChars varchar(100))
    RETURNS varchar(500) AS
    BEGIN
    While @myString like '%[^' + @validChars + ']%'
    Select @myString = replace(@myString,substring(@myString,patindex('%[^' + @validChars + ']%',@myString),1),'')
    Return @myString
    END
    Go
    Declare @testStr varchar(1000),
    @i int
    Set @i = 1
    while @i < 255
    Select
    @TestStr = isnull(@TestStr,'') + isnull(char(@i),''),
    @i = @i + 1
    Select @TestStr
    Select dbo.GetCharacters(@TestStr,'a-z')
    Select dbo.GetCharacters(@TestStr,'0-9')
    Select dbo.GetCharacters(@TestStr,'0-9a-z')
    Select dbo.GetCharacters(@TestStr,'02468bferlki')
    perfect soluction

  • How do I remove the cells from footer in Pages 5.5.2?

    In the new Pages, version 5.5.2, my footers have cells. I want to have only one cell but can't find a way to remove the cell barriers.

    In your Toolbar, select Document, and then turn off the footer only. Then, set View ▸ Show Layout. You will want to also Hide Word Count to get it out of your way.
    Now, you can put something creative there that contains your text, or image content. For instance a Text box that is the same size as a footer, properly aligned using the yellow guidelines. Insert a right-justified Page number. Select the Text box, and then choose Arrange ▸ Section Masters ▸ Move Objects to Section Master. If from the Toolbar Documents Section tab, you choose to add another section after the current one, that Page number will auto-increment in the next section.

  • 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();
    }

  • JTree cell renderer: how to fill whole row?

    hi,
    i'm trying to make a tree cell renderer that renders at default height, but fills the horizontal width of the tree (e.g. with a JLabel with a custom background color). I'm working on the theory that in order to do this you need to change the preferred size of the component used to stamp the image at render time.
    The problem is that the preferred width then needs to be set to a value that depends on the context of the particular node (e.g. a deeply nested child node will be further to the right than the root node).
    I can't seem to find a method to say where the rendering starts though - does anyone know a way?
    (also if not then would setting the width to some astronimcal value break anything?)
    thanks,
    asjf

    Try this one, it will higlight the background and foreground colors of entire rows.
    Oscar
         class TableRenderer
              extends DefaultTableCellRenderer
              implements ListCellRenderer
              private boolean focused = true;
              private JLabel renderer;
              public TableRenderer()
                   super();
                   renderer = new JLabel();
                   renderer.setOpaque(true);
              public Component getListCellRendererComponent(
                   JList list,
                   Object value,
                   int index,
                   boolean isSelected,
                   boolean cellHasFocus)
                   return renderer;
              public Component getTableCellRendererComponent(
                   JTable table,
                   Object value,
                   boolean isSelected,
                   boolean hasFocus,
                   int row,
                   int column)
                   renderer =
                        (JLabel) super.getTableCellRendererComponent(
                             table,
                             value,
                             isSelected,
                             hasFocus,
                             row,
                             column);
                   /* Make the Labels border empty and indented */
                   setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
                   /* This is used to create alternate row colors */
                   Color bgColor = Color.white;
                   if (row % 2 == 0)
                        bgColor = new Color(237, 243, 254);
                   /* if the table has focus and the row is selected use these colors */
                   if (table.hasFocus() && table.getSelectedRow() == row)
                        table.setSelectionForeground(Color.WHITE);
                        table.setSelectionBackground(new Color(101, 137, 178));
                   /* if the table has not the focus but the row is selected use these colors */
                   else if (
                        table.hasFocus() == false && table.getSelectedRow() == row)
                        table.setSelectionBackground(new Color(196, 196, 194));
                   /* if not use the standard color */
                   else
                        renderer.setBackground(bgColor);
                        table.setSelectionForeground(SystemColor.textText);
                   if (value instanceof ColorData)
                        ColorData cvalue = (ColorData) value;
                        setForeground(cvalue.color);
                        setText(cvalue.data.toString());
                                /* Set the Labels value */
                   setText(String.valueOf(value));
                   return renderer;
         }

Maybe you are looking for

  • What's new in Project Siena Beta2

    1. A big push on services. Please see S. Somasegar's blog post. You will be able to make apps with modern functionality like social connections, web intelligence, translate and text to speech. Not just read, but also update. Not just static, but dyna

  • Triggering and reading on two HP/Agilent 34401A DMMs at same time

    Hi folks, I'm VERY new to LabVIEW and need some help with a measurement.  I'm using LV 8.2 with all equipment on GPIB.  I have two 34401A multimeters, triggered externally using an HP 33120A function generator.   I've downloaded the example vi's and

  • Is it possible to have a floating point representation in an array in LabVIEW?

    Could anyone be able to tell me how I would go about creating a part of a Vi that would create a user defined N random arrays of user defined length consisting of floating point representation? The values in the array cannot be limited to 0 and 1. Th

  • Horizontal image slide/scroll on mouseover

    Hi, n00b here, go easy! How is this gallery effect (link below) achieved, I've tried various searches for extensions, but I don't really know the correct terminology, so maybe thats why I'm not having much luck... http://www.myttonwilliams.co.uk/?id=

  • Photo Stream Folders

    I think I already know the answer since I'm not able to get it to work but just wanted to confirm that Photo Stream will only sync individual files and not folders, correct?  I have set my sync folder to My Pictures on my PC but when I import my phot