Setting color of an item in a Jcombobox in a JTable when editing

Hello,
I have a situation where I have a JCombobox in a JTable . The JCombobox is non-editable. The items within the combobox are colored in pink or blue in order to help the user differentiate between the two categories that are in the list.
But the problem is that when the user is on that cell and is just typing the first letter(s) in the combobox, he does see the item starting with that letter(s) but that item is not shown as colored. However, if the user clicks on the combobox with a mouse, the list pops-up and the items are shown as colored. I want the first part to work where the user can just use keyboard and see the items as colored in that cell itself. By default, currently when the row is selected the foreground is white and background is black. I want that particularly when this combobox has focus and an item is selected, the foreground should be of the same color as the color of the item.
Can someone help?
Thanks a lot in advance.

Additional information on above:
I associate a customized renderer with the column of my table for which i want to set the colors.
TableColumn tc6 = jTableDRS.getColumnModel().getColumn(myDRSModel.FINANCECODE_COLUMN);
tc6.setCellRenderer(new ColorRenderer());
here is the renderer that I am using...
public class ColorRenderer extends JLabel implements TableCellRenderer {
protected Border noFocusBorder;
public ColorRenderer() {
noFocusBorder = new EmptyBorder(1, 2, 1, 2);
setOpaque(true);
setBorder(noFocusBorder);
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
Color foreground = null;
Color background = null;
Font font = null;
if(column == myDRSModel.FINANCECODE_COLUMN)
setFont((font != null) ? font : table.getFont());
String str = (String)value.toString();
if (!str.equalsIgnoreCase("SELECT ONE")) {
int y = financedesc.indexOf(str);
if((payreceiveind.get(y).toString()).equals("R")){
setForeground(Color.RED);
} else if((payreceiveind.get(y).toString()).equals("P")){
setForeground(new Color(147,112,240));
if(isSelected)
if((payreceiveind.get(y).toString()).equals("R")){
setForeground(Color.RED);
} else if((payreceiveind.get(y).toString()).equals("P")){
setForeground(new Color(147,112,240));
setBackground(table.getSelectionBackground());
else{
setBackground(table.getBackground());
else
if(isSelected)
setForeground(table.getSelectionForeground());
setBackground(table.getSelectionBackground());
else
setForeground(table.getForeground());
setBackground(table.getBackground());
setValue(value);
return this;
protected void setValue(Object value) {
setText((value == null) ? "" : value.toString());
}

Similar Messages

  • Setting color for cells in a particular column of a jtable

    Hi, I know how to set the color for a cell in a column if the cell contains an Integer object and if I have default Integers already in the JTable when I begin. However I want the JTable to look blank at the beginning. As I can't make an Integer object invisible on the JTable I need to specify the colum in which I want the cells to change color in. I want to specify the column some how and then when the table later has Integers in it i can do a comparison to decide whether i want to change the color or not. Does anyone know how I will do this.
    Please HELP.

    1) You need to set the tooptip text on the renderer for the column (yourTable.getColumnModel().getColumn(...).getHeaderRenderer()).
    2) The header is a separate component to the table. When you add a table to a scroll pane it automatically adds the header to the scroll pane too. You can get the component (yourTable.getTableHeader()) and add it to your own container if you wish.

  • Set color for selected item?

    i was wondering if it is possible to setBackground and setForeground for JMenu, JMenuItems or any items that are selected? I know it is possible for JList because it has the function setSelectionBackground and setSelectionForeground but are there any functions that do that for these classes?

    This was originally posted by xhunterx:
    The fastest way I know to change that property for all instances of a JMenu or JMenuItem in an application is to simply change the UIDefaults for that property via UIManager.<I>put()</I>. Try this (changes the selection background for both menu and menuitems to Color.green):
    <pre>import java.awt.*;
    import javax.swing.*;
    <br>
    public class MenuDemo extends JFrame
    public MenuDemo() throws Exception
    UIManager.put("Menu.selectionBackground", new javax.swing.plaf.ColorUIResource(Color.green));
    UIManager.put("MenuItem.selectionBackground", new javax.swing.plaf.ColorUIResource(Color.green));
    <br>
    JMenuBar menuBar = new JMenuBar();
    JMenu menuOne = new JMenu("One");
    JMenu menuTwo = new JMenu("Two");
    JMenuItem itemOne = new JMenuItem("One Sub One");
    menuOne.add(itemOne);
    menuBar.add(menuOne);
    menuBar.add(menuTwo);
    getContentPane().add(menuBar,"North");
    setSize(200,200);
    setVisible(true);
    <br>
    public static void main(String args[]) throws Exception { new MenuDemo(); }
    }</pre>
    - Mark

  • Problem with setting tooltips for items of a JCombobox

    hi guys,
    I want to set tooltips for items of JComboBox & the code that i have written is given below , but the tooltip text is set for all the items of Nonitindustrycombo but the tooltips remain the same even for Nonitdesgcombo's items.
    Is that we need to refresh the ComboboxRenderer every time ?
    I am not able to trace out the exact reason for this,please if anyone can suggest me something regarding this would be of great use to me.
    class Searchpanel extends JPanel {
    String[] str = null;
    public SearchPanel(){
    Nonitindustrycombo.addItem("--Select--");
    ArrayList NonITindus = ERPModel.getAllNonitIndustry(); //gets all the items(strings) for Nonitindustrycombo
    for (Iterator iter = NonITindus.iterator(); iter.hasNext();) {
    String str = iter.next().toString();
    Nonitindustrycombo.addItem(str);
    SetTooltip(Nonitindustrycombo,NonITindus);
    Nonitdesgcombo.addItem("--Select---");
    ArrayList desg = ERPModel.getAllNonitDesg(); //gets all the items(strings) for Nonitdesgcombo
    for (Iterator iter = desg.iterator(); iter.hasNext();) {
    Nonitdesgcombo.addItem(iter.next());
    SetTooltip(Nonitdesgcombo,desg);
    class MyComboBoxRenderer extends BasicComboBoxRenderer
    public Component getListCellRendererComponent(JList list, Object value,
    int index, boolean isSelected,
    boolean cellHasFocus)
    if (isSelected)
    setBackground(list.getSelectionBackground());
    setForeground(list.getSelectionForeground());
    if (0 < (index))
    list.setToolTipText(str[index - 1]);
    else
    setBackground(list.getBackground());
    setForeground(list.getForeground());
    setFont(list.getFont());
    setText((value == null) ? "" : value.toString());
    return this;
    private void SetTooltip(JComboBox combo,ArrayList arr){
    str = (String []) arr.toArray (new String [arr.size ()]);
    combo.setRenderer(new MyComboBoxRenderer());
    public static void main(String[] args){
    new SearchPanel();
    Thanks ,
    vishal

    1) You where given a working example in your last posting on this topic. Compare your code with the working code to see whats different and fix it.
    2) The code you posted doesn't compile.
    3) You didn't use the "Code Formatting Tags" when you posted your code so it not readable.

  • A quick way to set different color for certain items in JList?

    is there a quick way of setting different color for certain items in JList?

    Either use HTML strings as the values in your JList (quickest, but may not be the most convenient, especially if your model isn't just text), or create your own ListCellRenderer (e.g. extend DefaultListCellRenderer).
    There is no such thing as "list.setItemForeground(int index, Color c)". You'll have to use one of the methods above.

  • How to color an item in a JComboBox?

    I need to color some item of my JComboBox,.
    or color the string text or the background of the single item
    anyone can help me?

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test3 extends JFrame {
      public Test3() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        Object[] data = { new ColoredObject(Color.RED,"Hello"),
                          new ColoredObject(Color.BLUE,"World,"),
                          new ColoredObject(Color.CYAN,"These"),
                          new ColoredObject(Color.GREEN,"Are"),
                          new ColoredObject(Color.MAGENTA,"Some"),
                          new ColoredObject(Color.ORANGE,"Colors")
        JComboBox jcb = new JComboBox(data);
        jcb.setRenderer(new ColoredRenderer());
        content.add(jcb, BorderLayout.NORTH);
        setSize(300, 300);
        setVisible(true);
      public static void main(String[] arghs) { new Test3(); }
    class ColoredObject {
      Color color;
      Object object;
      public ColoredObject(Color color, Object object) {
        this.color=color;
        this.object=object;
      public Object getObject() { return object; }
      public Color getColor() { return color; }
      public String toString() { return object.toString(); }
    class ColoredRenderer extends DefaultListCellRenderer {
      public Component getListCellRendererComponent(JList list, Object value,
                                                    int index, boolean isSelected,
                                                    boolean hasFocus) {
        Component c = super.getListCellRendererComponent(list, value, index,
            isSelected,hasFocus);
        if (!isSelected && !hasFocus && value instanceof  ColoredObject) {
          c.setBackground(((ColoredObject)value).getColor());
        return c;
    }

  • HOw to change the color of an item

    Say i want to change the background color of an item when it is selected. How to do it?

    And use a Post-text-item trigger to set the color back to its original:
    DISPLAY_ITEM(:SYSTEM.TRIGGER_ITEM,NULL);
    Unfortunately the PTI trigger does not run on List Items , so you might need special code to set those fields back to their original color.

  • Apply Fill Color to Group Item with Applescript

    Is it possible to set the fill color of a group item using applescript and CS3? The group contains paths and text that have the same fill color with no strokes.I am able to select the group and delete it or move it (with applescript) but have had no success in setting the fill color.
    Thank you in advance for help on this question. And thanks for everything I have picked up from browsing.

    Now that I am addressing the path items and text items of the group separately I am having some success. Now I am having difficulty getting the correct terms for assigning a Spot Color to the file. Here is a piece of the script.
    This works:
    tell application "Adobe Illustrator"
    set openDoc to document 1
    set ftClr1 to (first group item whose note is "Front3") of openDoc
    set ftClr1Paths to path items of ftClr1
    repeat with thisPath in ftClr1Paths
    set fill color of thisPath to {red:255}
    end repeat
    set textFrames to text frames of ftClr1
    repeat with thistext in textFrames
    set fill color of every line of thistext to {red:255}
    end repeat
    end tell
    Need help to set the fill color to a Spot Color that already exists in Swatches.
    Thanks
    Nick

  • Backgroung color of displayed item

    Hi,
    I want to set the backround of an item accordig to its canvas background.
    I was trying:
    canvas_color .= := get_canvas_property('CANVAS_NAME, background_color);
    set_item_property('BLOCK.ITEM_NAME', background_color, canvas_color);
    This does'nt work successfuly as canvas background property is set to <default>, and get_canvas_property returns is null
    Do you have any suggestions of how to overcome this problem?
    I don't want to solve this problem by assigning a real rgb value (as mentioned eg in background color of display item )

    Hi
    I do not know perhaps following code will help to
    solve your problem.
    1.You have to create a VISUAL_ATTRIBUTE and define the
    background color
    2.Use this little example.
    DECLARE
    cn_id CANVAS;
    BEGIN
    cn_id := FIND_CANVAS('canvas2');
    SET_CANVAS_PROPERTY(cn_id,VISUAL_ATTRIBUTE,'MY_VISUAL_ATTRIBUTE');
    END;

  • Applescript to change color of path items with specific swatch from swatch group, multiple times

    I am attempting to take a path item that is on its own layer and change its color multiple times, saving it each time.
    I was able to do it with javascript however can't get it to work in applescript.
    Javascript:
    (Items are already selected that I intend to change.)
    var iL = app.activeDocument.pathItems.length;
    var colorSwatches = app.activeDocument.swatchGroups.getByName('newColors');
    var allColors = colorSwatches.getAllSwatches();
    var colorNames = Array();
    for (var i = 0; i < allColors.length; i++){
        colorNames.push(allColors[i].name);
    for (x = 0; x<colorNames.length; x++)
            var currentColor = allColors[x].name;
            for (i=0; i<iL; i++)
                var myItem = app.activeDocument.pathItems[i];
                if(myItem.selected)
                    myItem.fillColor = app.activeDocument.swatches.getByName(currentColor).color;
    (I then go on to save each one)
    When trying to cross over into applescript I have the following so far:
                   set iL to count every path item of document 1
                   set colorSwatches to swatchgroup "newColors" of current document
                   set allColors to get all swatches colorSwatches
                   set swatchCount to count every item in allColors
                   repeat with i from 1 to swatchCount
                        set currentSwatch to item i of allColors
                        repeat with x from 1 to iL
                            set myItem to path item i of document 1
                   here is where I have no idea what I am doing... I can't figure out how to test if an item is selected
                            if myItem's has selected artwork is equal to true then
                                set fill color of myItem to {swatch:currentSwatch}
                            end if
                        end repeat
                   end repeat
    Or better yet is there a way I can select every path item of a layer and change its color that way?
    Something like the following:
              set fill color of every path item of layer "art" of document 1 to {swatch:currentSwatch}
    Thanks for any input!

    I'm throwing it into a Applescript OBJc project I am working with. I currently have it in a javascript file within the actual project however this is the slowest part of my project and I'm going to attempt to speed it up some.
    Let's say I'm changing the color of a path item 35 times... this starts to eat a ton of time up.
    My applescript save illustrator file as jpeg is much faster than the javascript one for some reason...
    It's also something I have needed to do numerous times in the past and never got around to asking.

  • Setting Color to hyperlinks

    Hi
    How to set color, underline, blinking to hyper links
    thanks
    ~noc

    You can create a non-editable text item with font colour blue (or whatever your like),
    set the font style : Underline (I have tried this property on 9i & 10g, it works in 10g, not in 9i)
    create a when-mouse-click trigger on this text item, and in this trigger use WEB.SHOW_DOCUMENT
    For blinking you can use a timer and WHEN-TIMER-EXPIRED trigger at form level
    (but using a timer for making item values blink is not a good option, because they consume resources)
    (I think all of this can be done with PJCs, but I dont know much about them)

  • Setting color codes for more than one photo at a time

    Is there any way to set color codes for more than one photo at a time?

    Hi John,
    I will look at keywords. My issue is speed. Right now I am culling and editing an event shoot that spanned a week with 35 separate events and more than 5000 images. So I use the fastest most convenient method I can and it still takes a long time to have a completed and final shoot. On this shoot I will end up with a final set of around 1500 images. Right now I am finishing processing a show that will hang in the Deutsches Amerikanish Zentrum in Stuttgart.
    As I am sure you are aware by now, having seen enough of my inane questions that over the last two years or since Lightroom version 1.xx if I could not figure out how to do something I skipped it. So many things in Lightroom are buried and unless you have a mind like a steel trap (and think that some of you guys in the forum do) locating how to do something is not obvious.
    For example, I only learned (in the last hour) that I could assign colors as a group of selections by using Shift + number. I found this in a side head in Martin Evenings Lightroom book. I still do not know how to find a way to display the color filter "selection" set in Library mode. Is there a way?
    To top it off, Stuttgart Media University asked me if I would add a Lightroom module to my schedule this year. Now I have a compelling reason to learn all those missing pieces that I have created workarounds for. Hence the number of posts you have been seeing from me over the past few of weeks.
    I tell my class that there are no such things as stupid questions, only questions. Now I am practicing what I have been preaching for the last gazillion years. Guys like you have been great.
    My workflow is
    1. I first separate all images by event. I do that at the time of import.
    2. I do a fast pass rejecting all the obviously bad images
    3. I do a second pass grouping the images by sub-group (speeches, people talking, performances, etc.) This is where I run out of selection methods and your key-wording could work but it would probably take too much time to establish a keyword set for a single event. Where I have more than five subgroups I set up different collection sets with one collection for each sub group. However I would like to keep a single event in one collection.
    4. I then select the images to be used by color code.
    5. Next I process the final images (crop develop etc) by collection.
    6. Last I output the set according to client requirement.
    If you have a better workflow, I am all ears.
    By the way, what is your photo specialty and where are you located?
    Jim

  • Mapping in BPM - set value of collection item

    Hello,
    is it possible to set value to exact item of collection in mapping step in netweaver BPM?
    I need something like set(<collection_variable>,<item_index>,<item_value>)  - so exact opposite of GET generic function, which gets specific item from collection.
    Is it possible in NW BPM?

    You dont have to apologize. I didnt meant that as offend.
    I appreciate the possibility to discuss that topic with somebody, because discussion itself sometimes shows other perspective to the problem, which can lead to solution
    Of course I wrote EJB function to solve that - but I cant believe that it isnt standard solution to that pretty common use case.
    I think, that problem lays in very limited implementation of XPath into Netweaver BPM. I will bet my left hand, that in some future SP of BPM will SAP introduce something like this:
    myCollection[1]/notificationId = notificationId
    which is standard XPath way to do that

  • The color of text item with multi-line in web

    I tried to change the background color of text item with multi-
    line, but it does not work when I run in the web, if some body
    knows that, please give a hint.
    Thanks
    Frank
    null

    I tried to change the background color of text item with multi-
    line, but it does not work when I run in the web, if some body
    knows that, please give a hint.
    Thanks
    Frank
    null

  • To set color for barchart having datetime column

    Hi,
       I have a datetime column in the XSD,
    I was trying to set colors for the barchart through,  chart expert --> colorhighlight  ,here in  colorhighlight when i click on new I am getting a dialogue box asking to enter datetime in M:D:YYYY H:MM:SS TT format. why is this dialogue displayed ? How to overcome this.
    Regards,
    Deepa V

    Hi Deepa
    Please inform us with the following information:
    1: What is the version of Crysatl Reports that you are using?
    2: What is the Chart Type that you are uisng?
    3: Where are you placing this chart in the report?
    Regards
    Ashwini Yadav

Maybe you are looking for

  • About file audio/video file type and name of jpeg ...

    Can anybody please tell Following few things   1- If I record a telephone call (conversation) in Nokia N70, what is the file format i.e. wav, mp3, rm  or what and what is the initial name of the file e.g. nokia70-001.wav, nokia70-002.wav etc or what?

  • Green Zoom Button No Longer Works

    When I click the green zoom button for a quicktime video, the window no longer zooms. Is there a way to remedy this? I already installed and reinstalled.

  • FAQ/StreamWork Integration Wiki

    Please also checkout the information in the [StreamWork Integration API Wiki|http://wiki.sdn.sap.com/wiki/display/SWAPI/StreamWorkIntegrationAPI+Wiki] before asking questions. To get started the Wiki will contain sections on each of the StreamWork AP

  • Canon PowerShot G11 won't mount on iMac, will mount on MacBookPro

    We have a Canon PowerShot G11. It refuses to mount (either through iPhoto, Image Capture, or Disk Utility) when plugged into our iMac (iMac10,1) 3.06 Intel Core Duo. We plug the USBcable directly into the iMac. The iMac is running 10.6.5 We also have

  • "printer installer" window shows up at every boot after installing printer

    After installing successfully a Samsung printer, everytime I boot Mountain Lion there is a  "printer installer" window shows up. Any way to get rid of this? Regards, Vincent