Selection color in jtable

I've noticed one annoying thing about JTable when running under Windows L&F. Namely, a table without focus renders its selection in the same color as a table with a focus. This can get really annoying especially with windows where containing more than one jtable.
Is there an good way of telling JTable to use a different color for selection when it doesn't have the focus?

thanks, that worked. here's what i ended up donig:
         addFocusListener(new FocusListener() {
            private Color selectionBackground = getSelectionBackground();
            private Color selectionForeground = getSelectionForeground();
            public void focusGained(FocusEvent e) {
                setSelectionForeground(selectionForeground);
                setSelectionBackground(selectionBackground);
            public void focusLost(FocusEvent e) {
                if( !e.isTemporary()) {
                    setSelectionForeground(UIManager.getColor("inactiveCaptionText"));
                    setSelectionBackground(UIManager.getColor("inactiveCaption"));
        });not too sure if inactiveCaption* is the best key to use, but I couldn't find anything better. Any ideas?
Thanks
Dmitry

Similar Messages

  • How to get the default selection color from JTable

    Hi, there,
    I have a question for how to get the default selection color from JTable. I am currently implementing the customized table cell renderer, but I do want to set the selection color in the table exactly the same of default table cell renderer. The JTable.getSelectionBackgroup() did not works for me, it returned dark blue which made the text in the table unreadable. Anyone know how to get the window's default selection color?
    Thanks,
    -Jenny

    The windows default selection color is dark blue. Try selecting any text on this page. The difference is that the text gets changed to a white font so you can actually see the text.
    If you don't like the default colors that Java uses then use the UIManager to change the defaults. The following program shows all the properties controlled by the UIManager:
    http://www.discoverteenergy.com/files/ShowUIDefaults.java
    Any of the properties can be changed for the entire application by using:
    UIManager.put( "propertyName", value );

  • JTable - DefaultTableCellRenderer overrides selection color

    According to the Api Docs, the setBackground method of the DefaultTableCellRenderer class should only "assign the unselected-background color to the specified color". In fact, it also seems to set the selection color: each cell with a DefaultTableCellRenderer which changes the Color does not get highlighted when selected. Even if I set the value to "null" no selection is visible.
    The same problem happens with setForeground ...

    In the 'How to use Tables' Java tutorial the default renderer's constructor has the following:
    setOpaque(true); //MUST do this for background to show up.
    Could this help you?
    Is the highlighting of the cell in any way tied to the cell editor as opposed to the cell renderer?

  • Select columns in jtable

    Hello,
    I have a JTable component with 4 columns. I only allow single row selection. If I select a row not all columns are selected. The one you clicked on does not have the selection color. Ho can you select all columns with the selection color ?
    regards
    Johan

    Just guessing because I had a hard time wading though all your code. you probably have a custom renderer on that column. Your renderer needs to change the background color if the cell is selected.

  • Background Selection Color

    I made a JTable in which you can set the row background color as you like for every row independently.
    The problem is that I would like the selection color to change accordingly to the background of the selected row (as it happens in many common programs such as Excel or Word). Is there any way to make it without implementing a palette that customizes the couples "Background Color" - "Selection Color"?
    Thanks in advance,
    Andrew.

    try the below code hope this is what u r looking for
    good luck.
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class SelectionBackgroundColor extends JFrame
    JScrollPane jScrollPane1 = new JScrollPane();
    JTextArea jTextArea1 = new JTextArea();
    JPanel jPanel1 = new JPanel();
    JButton chgBgColorButton = new JButton();
    public SelectionBackgroundColor()
    try
    jbInit();
    catch(Exception e)
    e.printStackTrace();
    public static void main(String[] args)
    SelectionBackgroundColor selectionBackgroundColor = new SelectionBackgroundColor();
    selectionBackgroundColor.show();
    private void jbInit() throws Exception
    chgBgColorButton.setText("Change Background Color");
    chgBgColorButton.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    chgBgColorButton_actionPerformed(e);
    jTextArea1.setWrapStyleWord(true);
    jTextArea1.setLineWrap(true);
    jTextArea1.setText(
    "I made a JTable in which you can set the row background color as " +
    "you like for every row independently.\nThe problem is that I would " +
    "like the selection color to change accordingly to the background " +
    "of the selected row (as it happens in many common programs such as " +
    "Excel or Word). Is there any way to make it without implementing " +
    "a palette that customizes the couples \"Background Color\" - \"Selection " +
    "Color\"?\n\nThanks in advance,\nAndrew.\n");
    jPanel1.add(chgBgColorButton);
    jScrollPane1.getViewport().add(jTextArea1);
    getContentPane().add(jScrollPane1, BorderLayout.CENTER);
    getContentPane().add(jPanel1, BorderLayout.SOUTH);
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    SwingUtilities.updateComponentTreeUI(this);
    pack();
    void chgBgColorButton_actionPerformed(ActionEvent e)
    JColorChooser jc = new JColorChooser();
    Color c = jc.showDialog(this, "Choose background color",
    jTextArea1.getBackground());
    if(c != null && !c.equals(jTextArea1.getBackground()))
    jTextArea1.setBackground(c);
    jTextArea1.setSelectionColor(new Color
    (255 - c.getRed(), 255 - c.getGreen(), 255 - c.getBlue()));
    c = jTextArea1.getSelectionColor();
    jTextArea1.setSelectedTextColor(new Color
    (255 - c.getRed(), 255 - c.getGreen(), 255 - c.getBlue()));
    jc = null;
    gkrao

  • Action written in CS4 won't run correctly in Elements 11 - specif. the "selective color" layer

    I created an action using Adobe Photoshop CS4, and it runs correctly in CS4.  When I save and load the action into Elements 11,  there is a problem with the selective color layer.  The selective color layer shows up in the layer stack along with the expected message that it can't be edited b/c it was created in the full version of Photoshop. However, the layer itself does not have any color/changes in it.
    In Photoshop, the selective color layer makes the photo look pink.  When I run the action in Elements11,the selective color layer does absolutely nothing to the photo.  I do have the eye turned "on" to view the layer, and it's set at the correct blending options & opacity (normal, 100%). 
    If I run the action in Photoshop, save the file with all the action-created layers, and reopen the file in Elements 11, THEN the selective color layer shows its correct pink color.  But when I run the action as a stand-alone action in Elements11, it does not.
    Can anyone offer help as to why this is happening? Is there something special I need to do to make the action work correctly in Elements 11? My understanding was that it should RUN and create the layers correctly, although some of them will not be editable in Elements11. However, as it stands, it is not creating them with the correct color.
    Thanks in advance for your help!

    You probaly need to record the action in a little different way in photoshop cs4 to get the selective color adjustment layer to work.
    Try something like this:
    1. In photoshop cs4 add an selective color adjustment layer, but don't do any adjustments and stop recording the action.
    2. Undo the selective color adjustment layer and then double click on on the selective color adjustment layer step in the actions panel
       and when the dialog opens set your adjustments and click ok.
    Now it should work in pse 11:

  • Select- Color Range- Results in Blue Screen (PC)  (driver out of date)

    I've been using the CS6 beta about two days.  While experimenting with color range I experienced two consecutive blue screen crashes.  The first time it happened,I was working with the color range selector and was replacing the selected areas with another color using the paint bucket.  About the third time I attempted this, my PC blue screened.  The second time, I opened a photo, went to Select>Color Range and got an immediate blue screen crash.
    I then went back to CS5 and I've been playing with the same scenario with no apparent problems.
    My PC is a store built computer.  It consists of an MSI 990-FXA GD80 motherboard, an AMD Phenom 1100t CPU, Asus GTX550 Ti graphics card and 8 gig of RAM.  It boots from a 60 gig SSD and my programs reside on a 500 gig hard drive.  The OS is Windows 7 Professional 64 bit.  CS6 is using the hard drive for its scratch disk and Photoshop is using 4339 mb of the 7232 mb of available RAM - I haven't changed that.  I'm running CS6 as administrator because the way it installed, it would only run in that fashion.
    One disappointment during the installation was CS6 made no attempt to read my preferences from the CS5 install.  That may be covered in another post, I've not yet looked.
    Please keep us informed as new betas are released, because I would like some time to work with this puppy before plunking down big bux for the upgrade.  As it is now, I'm going back to CS5.  I get mighty nervous when my super computer blue screens!
    Gerry
    gswetsky AT bellsouth DOT net

    The GPU is often at root of issues like yours. I've had so many problems with Nvidia drivers for their gaming-oriented adapters (like yours) that I finally went with one of their workstation cards. I have a Quadro card with just enough RAM to make Photoshop happy. The workstation drivers are optimized for reliability, the consumer card drivers are optimized for gaming and that often means they're less stable and reliable with Photoshop.

  • Multi color gradient for touch and selected color of spark mobile list

    multi color gradient for touch and selected color of spark mobile list
    how to get dat?

    or how about a bitmap as the background for the touch and selected color for the items in a list.

  • Selection Problem with JTable

    Hello,
    i have a selection problem with JTable. I want to allow only single cell selection and additionally limit the selection to the first column.
    I preffered the style from MS Outlook Express where you can select the email accounts to edit.
    It is a table like this:
    Account name  |   Type  |   ...
    --------------|---------|---------------------
    Hotmail       |   POP3  |
    GMX           |   IMAP  |The selection should be only avaibable at 'Hotmail' or 'GMX' - not at 'POP3', 'IMAP' or as complete row selection.
    Please help me!
    Thanks.
    Warlock

    Maybe this will helpimport java.awt.*;
    import javax.swing.*;
    public class Test3 extends JFrame {
      public Test3() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        String[] head = {"One", "Two"};
        String[][] data = {{"R1-C1", "R1-C2"}, {"R2-C1", "R2-C2"}};
        JTable jt = new JTable(data, head);
        jt.getColumnModel().setSelectionModel(new MyTableSelectionModel());
        content.add(new JScrollPane(jt), BorderLayout.CENTER);
        jt.setCellSelectionEnabled(true);
        jt.setRowSelectionAllowed(false);
        jt.setColumnSelectionAllowed(false);
        setSize(300, 300);
        setVisible(true);
      public static void main(String[] arghs) { new Test3(); }
    class MyTableSelectionModel extends DefaultListSelectionModel {
      public void setSelectionInterval(int index0, int index1) {
        super.setSelectionInterval(0, 0);
    }

  • How can I change the 'selected' color of one JToggleButton only.

    Hi,
    This seems like a simple / trivial question, but I just can't figure it out. Is there a way that I can create a JToggleButton and change the selected color of only that JToggleButton.
    I'm trying to create a simple sidebar like component for navigation within my app. A group of JToggleButton[s] added to a ButtonGroup (with the proper layout / sizing) works great, but the default JToggleButton colors don't suit my needs. I know that I can change the colors using the UIManager / UIDefaults, but I don't want to change the defaults for every JToggleButton in my app. I only want to change the defaults for a few select JToggleButton[s].
    For example, I can do this:
    UIManager.put("ToggleButton.select", UIManager.getColor("Table.selectionBackground"));
    UIManager.put("ToggleButton.background", UIManager.getColor("Table.background"));but I'd rather do something like this:
    JToggleButton jtb = new JToggleButton("Toggle Button Text");
    jtb.setSelectedColor(UIManager.getColor("Table.selectionBackground"));
    jtb.setBackground(UIManager.getColor("Table.background"));The only thing is, I can't find any method that is the equivilant of 'setSelectedColor(Color)' for JToggleButton.
    I know I could do it by adding some listeners to the JToggleButton[s], but that seems a little complicated for something like changing a color.
    I'd also seen a solution in the forums where someone had extended the ButtonUI of the pluggable look and feel they were using. I'm not interested in modifying the look and feel I'm using. As far as I'm concerned, that would defeat the purpose of having a pluggable look and feel as I would have to duplicate my efforts for every look and feel I want to use.
    Any help would be appreciated,
    Ryan

    try this
    import javax.swing.*;
    import java.awt.*;
    class Testing extends JFrame
      public Testing()
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(250,75);
        setLocation(400,300);
        JPanel jp = new JPanel();
        JToggleButton jtb = new JToggleButton("Toggle me");
        jtb.setUI(new MyUI());
        jp.add(jtb);
        getContentPane().add(jp);
      public static void main(String args[]){new Testing().setVisible(true);}
    class MyUI extends javax.swing.plaf.metal.MetalToggleButtonUI
      public Color getSelectColor(){return Color.BLACK;}
    }

  • Photoshop CS2 crashes when opening selective color

    Every time I try to open image/adjust/selective color the program crashes.
    It has also started crashing after I save a file.
    I have tried uninstalling and re-installing the program, but to no avail.
    I'm using a Mac Mini OSX 10.4.1 with 1 GB ram.
    I've been running CS2 on this computer for 2 years without a hitch.
    Any fix or advice would be appreciated.

    I would suggest updating to 10.4.11 as there have be many bug fixes since 10.4.1

  • How to get "Selected" color for custom toolbar buttons?

    RH 8.0.2.208
    RoboHelp HTML
    WebHelp output
    I'm getting flack from internal QA folks about the custom toolbar buttons not having the same "selected" color as the default buttons (Contents, Index). I've copied the background color info from the <btnselected></btnselected> section for the built-in Contents to the <btnselected></btnselected> section for a custom toolbar button, but RH is ignoring it.
    Any hints?
    Leon

    You could try using the raw converter. Open one file and edit it (File>Open, pick the image and choose Camera Raw as the format before you click Open). Then open the next image and click the little four-lined square on the upper right side of the ACR window and choose Previous Conversion from the flyout menu.

  • Black and white selective coloring with brushes disappeared

    The down and dirty:
    Upgraded to Aperture 3.1.1
    Aperture then updated my library
    I open a file that I have selectively colored with black and white (a track and field runner and her lane is color, the field is black and white) and to my horror the thumbnail and "quick preview" is correctly colored, but the full resolution image is not
    How do I get my hard work back?

    I'd like to add one last bit that seems strange to me (and gives me hope that I can recover my edits). When I switch "quick preview" from on to off and the image zooms to the native resolution my edits are in tact for half a second before going away (the image fully loads - I'm not looking at an expanded rendering of the quick preview).
    Also, when I move the image at full zoom my B&W edits flash briefly until I stop moving the image.
    I tried repair permissions and repair database. Both failed.

  • I'm using an iMac running Os X Yosemite, Photoshop CS5 Extended, R2880 Epson printer  In the Print Settings dialog box, I can't select Color, Advanced BW or Grayscale unless I select "Printer Manages Color". The pull down menu is grayed out. Even with "pr

    I’m using an iMac running Os X Yosemite, Photoshop CS5 Extended, R2880 Epson printer  In the Print Settings dialog box, I can’t select Color, Advanced BW or Grayscale unless I select “Printer Manages Color”. The pull down menu is grayed out. Even with “printer manages color” the tif or jpg image comes out in color overlaid with black. (See example - printer1. image on left is close to what it should be). Photoshop has no updates pending. I’ve downloaded the latest Epson driver which was working fine just before the problem occurred

    Is your Photoshop CS5 updated to 12.1?
    Are you on Yosemite 10.10.1 or Yosemite 10.10.2?
    Did you apply the recent Epson software 2.1.9 update?
    What type of file is it (file format)?  What bit depth and what color space?
    BOILERPLATE TEXT:
    Note that this is boilerplate text.
    If you give complete and detailed information about your setup and the issue at hand,
    such as your platform (Mac or Win),
    exact versions of your OS, of Photoshop (not just "CS6", but something like CS6v.13.0.6) and of Bridge,
    your settings in Photoshop > Preference > Performance
    the type of file you were working on,
    machine specs, such as total installed RAM, scratch file HDs, total available HD space, video card specs, including total VRAM installed,
    what troubleshooting steps you have taken so far,
    what error message(s) you receive,
    if having issues opening raw files also the exact camera make and model that generated them,
    if you're having printing issues, indicate the exact make and model of your printer, paper size, image dimensions in pixels (so many pixels wide by so many pixels high). if going through a RIP, specify that too.
    etc.,
    someone may be able to help you (not necessarily this poster, who is not a Windows user).
    a screen shot of your settings or of the image could be very helpful too.
    Please read this FAQ for advice on how to ask your questions correctly for quicker and better answers:
    http://forums.adobe.com/thread/419981?tstart=0
    Thanks!

  • I have Photoshop CS5 and a Epson 3880 . The print setting dialogue box won't open when selecting color output PRINTER MANAGES COLORS

    I have Photoshop CS5 and a Epson 3880 . The print setting dialogue box won't open when selecting color output PRINTER MANAGES COLORS
    It does ope when selecting PHOTOSHOP MANAGES COLOURS . This is first time in 7 year this has happened.
    Any one with ideas/

    What is your screen resolution?
    What operating system?

Maybe you are looking for