Setting jtree objects' color

Hi all
I have a small (?) problem changing the background color of a jtree object.
I change the background color to black with setBackground method but the objects in it remains white. I want them to be in black background color, too. and I couldn't find a solution. How can I do that?
thanks

I have a small (?) problem changing the background
color of a jtree object.Do you mean the instance of JTree, or one of its nodes?
Just a few guesses - the Swing experts are in the Swing forum:
- maybe the tree background is transparent and you actually see the background of the pane it's on. Did you set the JTree to be opaque?
- did you think about custom renderers?

Similar Messages

  • Setting transparent fill color

    b How can I set the transparent color to a form object from a JavaScript code?
    For example in this case:
    > xfa.resolveNode("this.border.fill.color").value = "255,255,0";
    This line set the object color to yellow. And transparent color? How I have to do?
    Thanks !!!
    Dan

    While XFA supports any color space, the
    usable color space depends on the target. Since your forms are rendering to PDF (or possibly HTML if you're using LiveCycle Forms), you're unfortunately limited to their support which is RGB only.
    In short, you can't set the transparency value of a color when targeting PDF.
    Stefan
    Adobe Systems

  • How do you set the font color for a specific entire row inside a JTable?

    How do you set the font color for a specific entire row inside a JTable?
    I want to change the font color for only a couple of rows inside a JTable.
    I've seen some ways to possibly do this with an individual cell.
    Clarification on changing the font color in an individual cell would be helpful too if
    there is no easy way to do this for a row.

    hai,
    Try out with this piece of code.Create your table and assign the renderer to each column in the table.
    CellColorRenderer m_CellColorRenderer = new CellColorRenderer();
    for(int i=0;i<your_JTable.getColumnCount();i++)
    your_JTable.getColumnModel().getColumn(i).setCellRenderer(m_CellColorRenderer);
    class CellColorRenderer extends JLabel implements TableCellRenderer
    CellColorRenderer()     
    setOpaque(true);     
    setHorizontalAlignment(LEFT);
    setVerticalAlignment(CENTER);
    setBackground(Color.white);
    setForeground(Color.black);
    protected void setValue(Object value)
         setText((value == null) ? "" : value.toString());
    public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected, boolean hasFocus, int row,int column)
         if(isSelected == true)
              setForeground(Color.red);
         else
              setForeground(Color.black);
         setValue(value);
         return this;
    regards,
    bala

  • Setting the series color of a bi beans graph based on the data values

    How do I conditionally set the series color of a bi beans graph based on the data values?
    I am using the following code to get the data values and set the series color:
    Graph gr=(Graph)CmdrDashboardP1_pres1.getView();
    DataAccess da=gr.getGraphModel().getDataAccess();
    DataDirector dd=gr.getDataDirector();
    DataMap dm=dd.getDataMap();
    int re=dd.ROW_EDGE;
    int ce=dd.COLUMN_EDGE;
    Object val=da.getValue(re,ce,dm.DATA_TYPE);
    int seriesCount=da.getEdgeCurrentSlice(DataDirector.ROW_EDGE);
    if (val <=45.0)
    gr.getSeries().setColor(new Color(255,0,0),seriesCount);
    I get a NullPointerException from the line of code "Object val=da.getValue(re,ce,dm.DATA_TYPE)." I have tried the code with DATA_UNFORMATTED as well, but get the same exception. When I print the DataMap value of dm the results are [dataUnformatted, dataViewFormat, value, dataIsTotal, dataType].
    Also, I get the error "method <= (java.lang.Object,double) not found in class _CmdrDashboardP1" from the "if (val <=45.0)" code.
    Thanks for any assistance

    How do I conditionally set the series color of a bi beans graph based on the data values?
    I am using the following code to get the data values and set the series color:
    Graph gr=(Graph)CmdrDashboardP1_pres1.getView();
    DataAccess da=gr.getGraphModel().getDataAccess();
    DataDirector dd=gr.getDataDirector();
    DataMap dm=dd.getDataMap();
    int re=dd.ROW_EDGE;
    int ce=dd.COLUMN_EDGE;
    Object val=da.getValue(re,ce,dm.DATA_TYPE);
    int seriesCount=da.getEdgeCurrentSlice(DataDirector.ROW_EDGE);
    if (val <=45.0)
    gr.getSeries().setColor(new Color(255,0,0),seriesCount);
    I get a NullPointerException from the line of code "Object val=da.getValue(re,ce,dm.DATA_TYPE)." I have tried the code with DATA_UNFORMATTED as well, but get the same exception. When I print the DataMap value of dm the results are [dataUnformatted, dataViewFormat, value, dataIsTotal, dataType].
    Also, I get the error "method <= (java.lang.Object,double) not found in class _CmdrDashboardP1" from the "if (val <=45.0)" code.
    Thanks for any assistance

  • How do I set the background color of a page_item?

    I've been pasting "background-color:#5CD65C" in a number of places, like "HTML Table Cell Attributes" under the Label and the Element tabs, but get no results. Can anyone tell me how to set the background color of a cell, please?

    Hi Doug,
    Dynamic Actions is an alternative also, especially if it is conditional.
    Action Set Style
    Fire When Event Result Is True
    Style Name background-color
    Value #5CD65C
    Selection Type DOM Object
    DOM Object your item name
    Set your Condition Type and you have it.
    Jeff
    Edited by: jwellsnh on May 24, 2011 3:55 PM

  • How do you set default object settings

    I don't know how this happened but my default setting for object transparency got changed from "normal" to "color burn"
    (By selecting: Object - Effects - Transparency - then Color Burn or Normal) How can I switch this back so that the default is always on normal so I don't have to switch it from color burn to normal everytime I create a document?
    It took me an hour to figure out why objects were translucent. I kept thinking they were behind other objects and trying to bring them to the front, but they weren't. They were just set on color burn. I switched it back to mormal but everytime I start a new document, it defaults back to colr burn. Its driving me crazy.

    By the way, color burn is the default ONLY  when I draw cicles. If I draw a box, or any other shape the default is normal and works the way I want it to. Very odd.  Just a pain because everytime I draw a circle I gotta go through all these steps to set it back to normal so the colors don't burn through

  • JTree background color. How to...?

    I have set the background color of Jtree to pink and have used setOpaque(true). Now when ever I click on a node the node's color is not changing to the default blue color. How to change it?

    I have set the background color of Jtree to pink and have used setOpaque(true). Now when ever I click on a node the node's color is not changing to the default blue color. How to change it?

  • I set my black color to 75, 68, 67, 90 but it resets itself to 0, 0, 0, 100

    Everytime I set the fill/stroke color of objects in a file to 75, 68,67, 90 it resets it to 0, 0, 0, 100. It isn't consistent though... some objects accept the color. What could be going wrong?

    Yes, total ink depends on the paper.  Coated sheet could accept around 285 before pooling.  Depends on the press or digital printer, too.  If you set your Blacks, on screen and print to "accurate", then they will print at 100% Black or whatever percentage thereof.  I do not like the Appearance of Black settings in Adobe software.  To me, it should always be set to "Accurate", but my workflow is 98% print.  If I want a Rich Black, I just create a swatch of whatever combination that is appropriate and I don't have any problems.  So, it comes as a surprise you'd be having some problems.  My only guess was the Preference setting, but your Color Setting may have something to do with it, too.  If you solve it, I'd be interested in knowing what you did to solve it.

  • Is it possible to set a different color to part of a cell?

    Hi all,
    I am have trouble setting cell-specific Renderer.
    I have followed the instructions in the UISwing tutorial
    and extended JTable definition to overload getCellRenderer()
    to return myRenderer
    final JTable tableView = new JTable(dataModel){
    public TableCellRenderer getCellRenderer(int row, int column) {
    TableCellRenderer colorRenderer = new ColorRenderer();
    return(colorRenderer);
    My class definition for ColorRenderer is as follows:
    class ColorRenderer extends JLabel implements TableCellRenderer {
    public ColorRenderer() {
    public Component getTableCellRendererComponent(
    JTable table, Object color,
    boolean isSelected, boolean hasFocus,
    int row, int column) {
    setForeground(Color.blue);
    return this;
    Is it possible to set a different color to part of a cell?
    eg. I have "TEST,CELL,COLOR" as a string in a cell.
    Can I set a different color to the substring "CELL"?
    Your suggestions will be accepted most gratefully!
    Thanks in advance
    -Kalpana

    You should inherit your table cell renderer from a container, for example JPanel, add different JLabels to the panel and color them separately.
    Kurta

  • JTree - background color

    hello,
    iam trying to set the backgroung color of my tree, i tried using tree.setBackground(Color.gray) but it did not work, i checked out the documentation but it did not specify how to do that, please can someone help?
    asrar

    ah i finally got the solution, thanx ttarola for the renderer tip coz that did the trick, here is how i did it:
         DefaultMutableTreeNode top = new DefaultMutableTreeNode("Links");
         DefaultTreeCellRenderer linksRenderer = new DefaultTreeCellRenderer();
            createNodes(top);
            links = new JTree(top);
            links.putClientProperty("JTree.lineStyle", "Angled");
            linksRenderer.setBackgroundNonSelectionColor(Color.gray);//this did the trick
            linksRenderer.setBackgroundSelectionColor(Color.gray);
            linksRenderer.setLeafIcon(new ImageIcon("middle.gif"));
            links.setCellRenderer(linksRenderer);
            linkScroller = new JScrollPane(links);thanx guys for the suggestions and help.
    asrar

  • FormatType="number" sets different background color too

    Hi all!
    I have an af:table element and af:column inside that has formatType="number" to get the right-justified text. But beside right aligning the column values the column becomes gray. I don't like having text columns white and number columns gray in the same table. Is this a deliberate feature?
    I would like to set the background color to white, but background-color property for this column is not considered. If I set the background-color property for af_outputText inside this column I also don't get the desired look.
    Thanks!
    Take care!

    Hi Frank!
    I've created ADF read-only table for my view object. If I run the page immediately after this, all columns are white with gray headers which is OK. Then I change only the formatType property for one column:
    <af:column sortProperty="Mass"
                     sortable="false"
                     headerText="#{bindings.MyView.labels.Mass}"
                     formatType="number">
      <af:outputText value="#{row.Mass}">
      <f:convertNumber groupingUsed="false"
                                pattern="#{bindings.MyView.formats.Mass}"/>
      </af:outputText>
    </af:column>This makes the text in this column to be right aligned but also the column becomes gray.
    Hope to hear some more suggestions from you.
    Thanks, bye!

  • Automatically set the stroke color as fill color

    Hello all,
    I have a file with two squares with red and blue fill colors respectively and transparent surrounding strokes. I'm trying to find a way to automatically set the stroke color of each square to the respective fill color.
    Is there an Illustrator script somewhere that would achieve that? I am not aware of an internal Illustrator command for this purpose.
    Thank you

    I'm not a scripting guy at all, but getting an object's fill color and applying it elsewhere sounds like it should be scriptable. You should post the question in the AI Scripting Forum.
    The hitch I see here is your assertion that your objects have "transparent surrounding strokes." I could be wrong, but I believe there is actually no such thing in Illustrator. Through some simple experimenting, I conclude that an object's stroke set to "no color" by choosing the blank swatch actually becomes a stroke of undetermined, or perhaps zero, weight.
    Take an object with a stroke color and weight and set its stroke to no color. The weight goes away as well. One can't exist without the other, and vice-versa, with repect to stroke weight and color. Now enter a weight for that colorless stroke, and it again receives color; defaulting to black regardless of what it may have been previously.
    Similarly, if you assign a color where there is no weight, a 1-point weight appears by default.
    I'm not sure how/if that plays into your plans, but I just thought I'd ramble on about it here in case it's something you hadn't considered.

  • HELP!! set the cell color in jTable

    I need to set the color of a specific cell in jTable, but, I need to retain the old color in the jTable. It must not reset the whole table.
    would anyone help me in this problem... PLSSSSS its urgent

    A flexible variation on this is to specify formatting options in the JTable's client properties:
    // Use some sort of special "key" to indicate the cell and that you want to set the background color
    String key = "background:" + row + "," + column;
    table.putClientProperty(key, Color.green);You can then write a general table cell renderer that looks for these special formatting options and it doesn't disrupt your existing TableModel in any way:
    public class FormattingTableCellRenderer extends DefaultTableCellRenderer
      public Component getTableCellRendererComponent(JTable table, Object value, int row, int column, ...)
        Component component = super.getTableCellRendererComponent(table, value, row, column, ...);
        // See if the JTable specifies any properties to override the default format
        Color backgroundColor = (Color)table.getClientProperty("background:" + row + "," + column);
        if(backgroundColor != null)
          component.setBackground(backgroundColor);
        return component;
    }Any custom cell renderers you have then simply need to extend FormatTableCellRenderer instead of DefaultTableCellRenderer.
    It's very easy to add formatting options other than background, such as font, to the list of recognised attributes. You'll probably need to make some alterations to get it to recognise selection/focus but hopefully you get the idea.
    Hope this helps.

  • How do i set a multiple colors for a panel

    hi all,
    how do i set a multiple colors for a panel .pl desperately need a solution.
    regards
    bhaskar

    Iam contradicting self !
    Hope this helps !
    java.lang.Object
    |
    --java.awt.Component
    has the paint method ! Take the Graphics Object and call Graphics.setColor( Color.red ) .. and u can draw regular shapes like fillRoundRect. blah blah.. u need t count on the pixels .. I guess..
    An easier choice could be adding labels or panels with a layout of ur choice ..
    venu

  • JTree Object Serialization

    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.event.*;
    public class FileTree1 extends JFrame
    public static final ImageIcon ICON_COMPUTER = new ImageIcon("computer.gif");
    public static final ImageIcon ICON_DISK = new ImageIcon("disk.gif");
    public static final ImageIcon ICON_FOLDER = new ImageIcon("folder.gif");
    public static final ImageIcon ICON_EXPANDEDFOLDER = new ImageIcon("expandedfolder.gif");
    public String path;
    JTree m_tree;
    protected DefaultTreeModel m_model;
    protected JTextField m_display;
    public FileTree1()
    //super("Directories Tree");
    //setSize(400, 300);
    DefaultMutableTreeNode top = new DefaultMutableTreeNode(new IconData(ICON_COMPUTER, null, "Computer"), true);
    DefaultMutableTreeNode node;
    File[] roots =File.listRoots();
    for (int k=0; k<roots.length; k++)
    node = new DefaultMutableTreeNode(new IconData(ICON_DISK,null, new FileNode(roots[k])));
    top.add(node);
    node.add( new DefaultMutableTreeNode(new Boolean(true)));
    m_model = new DefaultTreeModel(top);
    m_tree = new JTree(m_model);
    m_tree.putClientProperty("JTree.lineStyle", "Angled");
    TreeCellRenderer renderer = new IconCellRenderer();
    m_tree.setCellRenderer(renderer);
    m_tree.addTreeExpansionListener(new DirExpansionListener());
    m_tree.addTreeSelectionListener(new DirSelectionListener());
    m_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    m_tree.setShowsRootHandles(true);
    m_tree.setEditable(false);
    JScrollPane s = new JScrollPane();
    s.getViewport().add(m_tree);
    getContentPane().add(s, BorderLayout.CENTER);
    m_display = new JTextField();
    m_display.setEditable(false);
    getContentPane().add(m_display, BorderLayout.NORTH);
    WindowListener wndCloser = new WindowAdapter()
    public void windowClosing(WindowEvent e)
    System.exit(0);
    addWindowListener(wndCloser);
    //setVisible(true);
    DefaultMutableTreeNode getTreeNode(TreePath path)
    return (DefaultMutableTreeNode)(path.getLastPathComponent());
    FileNode getFileNode(DefaultMutableTreeNode node)
    if (node == null)
    return null;
    Object obj = node.getUserObject();
    if (obj instanceof IconData)
    obj = ((IconData)obj).getObject();
    if (obj instanceof FileNode)
    return (FileNode)obj;
    else
    return null;
    // Make sure expansion is threaded and updating the tree model
    // only occurs within the event dispatching thread.
    class DirExpansionListener implements TreeExpansionListener
    public void treeExpanded(TreeExpansionEvent event)
    final DefaultMutableTreeNode node = getTreeNode(event.getPath());
    final FileNode fnode = getFileNode(node);
    Thread runner = new Thread()
    public void run()
    if (fnode != null && fnode.expand(node))
    Runnable runnable = new Runnable()
    public void run()
    m_model.reload(node);
    SwingUtilities.invokeLater(runnable);
    runner.start();
    public void treeCollapsed(TreeExpansionEvent event) {}
    class DirSelectionListener implements TreeSelectionListener
    public void valueChanged(TreeSelectionEvent event)
    DefaultMutableTreeNode node = getTreeNode(event.getPath());
    FileNode fnode = getFileNode(node);
    if (fnode != null)
    m_display.setText(fnode.getFile().getAbsolutePath());
    path=fnode.getFile().getAbsolutePath();
    System.out.println(path);
    else
    m_display.setText("");
    /*public static void main(String argv[])
    try
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    catch (Exception evt)
    new FileTree1();
    class IconCellRenderer extends JLabel implements TreeCellRenderer
    protected Color m_textSelectionColor;
    protected Color m_textNonSelectionColor;
    protected Color m_bkSelectionColor;
    protected Color m_bkNonSelectionColor;
    protected Color m_borderSelectionColor;
    protected boolean m_selected;
    public IconCellRenderer()
    super();
    m_textSelectionColor = UIManager.getColor("Tree.selectionForeground");
    m_textNonSelectionColor = UIManager.getColor("Tree.textForeground");
    m_bkSelectionColor = UIManager.getColor("Tree.selectionBackground");
    m_bkNonSelectionColor = UIManager.getColor("Tree.textBackground");
    m_borderSelectionColor = UIManager.getColor("Tree.selectionBorderColor");
    setOpaque(false);
    public Component getTreeCellRendererComponent(JTree tree,Object value, boolean sel, boolean expanded, boolean leaf,int row, boolean hasFocus)
    DefaultMutableTreeNode node =(DefaultMutableTreeNode)value;
    Object obj = node.getUserObject();
    setText(obj.toString());
    if (obj instanceof Boolean)
    setText("Retrieving data...");
    if (obj instanceof IconData)
    IconData idata = (IconData)obj;
    if (expanded)
    setIcon(idata.getExpandedIcon());
    else
    setIcon(idata.getIcon());
    else
    setIcon(null);
    setFont(tree.getFont());
    setForeground(sel ? m_textSelectionColor : m_textNonSelectionColor);
    setBackground(sel ? m_bkSelectionColor : m_bkNonSelectionColor);
    m_selected = sel;
    return this;
    public void paintComponent(Graphics g)
    Color bColor = getBackground();
    Icon icon = getIcon();
    g.setColor(bColor);
    int offset = 0;
    if(icon != null && getText() != null)
    offset = (icon.getIconWidth() + getIconTextGap());
    g.fillRect(offset, 0, getWidth() - 1 - offset,
    getHeight() - 1);
    if (m_selected)
    g.setColor(m_borderSelectionColor);
    g.drawRect(offset, 0, getWidth()-1-offset, getHeight()-1);
    super.paintComponent(g);
    class IconData
    protected Icon m_icon;
    protected Icon m_expandedIcon;
    protected Object m_data;
    public IconData(Icon icon, Object data)
    m_icon = icon;
    m_expandedIcon = null;
    m_data = data;
    public IconData(Icon icon, Icon expandedIcon, Object data)
    m_icon = icon;
    m_expandedIcon = expandedIcon;
    m_data = data;
    public Icon getIcon()
    return m_icon;
    public Icon getExpandedIcon()
    return m_expandedIcon!=null ? m_expandedIcon : m_icon;
    public Object getObject()
    return m_data;
    public String toString()
    return m_data.toString();
    class FileNode
    protected File m_file;
    public FileNode(File file)
    m_file = file;
    public File getFile()
    return m_file;
    public String toString()
    return m_file.getName().length() > 0 ? m_file.getName() : m_file.getPath();
    public boolean expand(DefaultMutableTreeNode parent)
    DefaultMutableTreeNode flag = (DefaultMutableTreeNode)parent.getFirstChild();
    if (flag==null) // No flag
    return false;
    Object obj = flag.getUserObject();
    if (!(obj instanceof Boolean))
    return false; // Already expanded
    parent.removeAllChildren(); // Remove Flag
    File[] files =listFiles();
    if (files == null)
    return true;
    Vector v = new Vector();
    for (int k=0; k<files.length; k++)
    //System.out.println(files[k].getName());
    File f = files[k];
    //if (!(f.isDirectory()))
    //continue;
    FileNode newNode = new FileNode(f);
    //System.out.println(newNode);
    boolean isAdded = false;
    for (int i=0; i<v.size(); i++)
    FileNode nd = (FileNode)v.elementAt(i);
    if (newNode.compareTo(nd) < 0)
    v.insertElementAt(newNode, i);
    isAdded = true;
    break;
    if (!isAdded)
    v.addElement(newNode);
    for (int i=0; i<v.size(); i++)
    FileNode nd = (FileNode)v.elementAt(i);
    IconData idata = new IconData(FileTree1.ICON_FOLDER,FileTree1.ICON_EXPANDEDFOLDER, nd);
    DefaultMutableTreeNode node = new DefaultMutableTreeNode(idata);
    parent.add(node);
    if (nd.hasSubDirs())
    node.add(new DefaultMutableTreeNode(new Boolean(false) ));
    return true;
    public boolean hasSubDirs()
    File[] files = listFiles();
    if (files == null)
    return false;
    for (int k=0; k<files.length; k++)
    //if (files[k].isDirectory())
    return true;
    return false;
    public int compareTo(FileNode toCompare)
    return m_file.getName().compareToIgnoreCase(toCompare.m_file.getName() );
    protected File[] listFiles()
    //if (m_file.isDirectory())
    //return m_file.listFiles();
    try
    return m_file.listFiles();
    catch (Exception ex)
    JOptionPane.showMessageDialog(null,"Error reading directory "+m_file.getAbsolutePath(),"Warning", JOptionPane.WARNING_MESSAGE);
    return null;

    The code which shown above is a JTree that shows complete file system.
    Please tell me how to persist the JTree Object using XMLEncoder and
    XMLDecoder for the above code.

Maybe you are looking for

  • Sales order item gets "Fully delivered" status even if partial qty

    Hello, We have a depot sales configuration in SAP. I found that some sales order lines are getting completed (delivery status "Fully delivered") even if partial quantity is pending for the order line. I checked the status in VBUP table where LFSTA ge

  • Repeated Error Messages when installing Reader 9.3 on Win7

    Recurring problem trying to install Adobe Reader 9.3 on WIN 7 PRO. ERROR 1305 - installation can't find AcroRead.msi - And the file is sitting in the Reader folder! ERROR 2203 - installer cannot open DB (e06734.ipi) SYS Error (2147287035) - This is a

  • Files and Desktop Shortcut gone??

    I seem to have lost all of the forms I created in the Adobe FormsCentral File and the desktop shortcut is missing. Any ideas what could have happened? Additionally, all of the forms I created and saved at *.pdfs using FormsCentral created forms are m

  • ISE 1.1.1 Android supplicant

    Hi Folks, I'm giving ISE 1.1.1 a go in the lab before I deploy it into our live wireless and I've hit a problem with the Android supplicant. I've finally gotten iOS to register and obtain the wireless profile, but when we try with an Android, the dev

  • Create an intercompany(IV) based on commercial invoice(F2)

    Dear Experts, Understand intercompany invoice can be created againest delivery but Is there any transaction to create intercompany invoice (IV) based on comercial invoice (F2). Actulay i want to consolidate muliple invoice(f2) to one IV. Regards Visw