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

Similar Messages

  • 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.

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

  • 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.

  • LR - Selective Coloring Techniques in Lightroom | The Complete Picture with Julieanne Kost | Adobe TV

    In this Episode of the Complete Picture Julieanne Kost explains two different methods for selectively colorizing an image to differentiate the subject from the background using Adobe Camera Raw.
    http://adobe.ly/ACTq9X

    Hello--When I use my adjustment brush with saturation set to -100, it is not taking out all the color from my photos.  Instead it adds a red hue.  Please advise as I would like to be able to selectively color my photos.

  • JTabbedPane selection color

    is it possible to change the default JTabbedPane selection color? (light gray)
    It doesnt seem to give you the ability to set a Renderer

    If altering the UI for your JTabbedPane is an option for you then this becomes pretty easy, just override the "paintTabBackground" method of BasicTabbedPaneUI. This isn't an option for a lot of people though... since that would pretty much limit you to one UI.
    Otherwise you will have set the background of the tab manually... the following code is an example of how to do this... unfortunatly... MetalTabbedPaneUI overrides the paintTabBackground method and DOESN'T use the manual backgrounds for selected tabs, it ALWAYS uses the default selectedColor from the UIManager... looks like an oversite to me... anyway... this code works fine with the Windows Look and Feel...
    import javax.swing.*;
    import javax.swing.event.ChangeListener;
    import javax.swing.event.ChangeEvent;
    import java.awt.*;
    * <pre>
    * SBTabbedPane
    * </pre>
    public class SBTabbedPane extends JTabbedPane {
         private Color tback;
         private int tsel = -1;
         private Color sback;
         public SBTabbedPane() {
              addChangeListener(new ChangeListener() {
                   public void stateChanged(ChangeEvent e) {
                        redoback();
         public void setSelectionBackground(Color c) {
              sback = c;
              redoback();
         private void redoback() {
              if (tsel >= 0) {
                   setBackgroundAt(tsel, tback);
              int i = getSelectedIndex();
              if (sback != null && i >= 0) {
                   tback = getBackgroundAt(i);
                   tsel = i;
                   System.out.println("SET BACK: " + tsel + ": " + sback);
                   setBackgroundAt(tsel, sback);
         public static final void main(String[] args) {
              try {
                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              } catch (Exception e) {}
              SBTabbedPane test = new SBTabbedPane();
              test.setSelectionBackground(new Color(255,0,0));
              test.add("Tab 1", new JLabel("HELLO"));
              test.add("Tab 2", new JLabel("WORLD"));
              JFrame testframe = new JFrame("Test Window");
              testframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              testframe.getContentPane().setLayout(new BorderLayout(0, 0));
              testframe.getContentPane().add(test);
              testframe.pack();
              testframe.setVisible(true);
    }Hope this helps a little...
    Josh Castagno
    http://www.jdc-software.com

  • Selection Color of JSlider

    I am making a GUI for a little software game.
    But i have a problem with my slider. I want to change the selection color from the tumb from the standard "beautiful" purple to another color.
    I've tried following settings , with UIManager.put("Slider.background",new ColorUIResource(Library.SETCOLOR)):
    Slider.background
    Slider.focus
    Slider.foreground
    Slider.highlight
    Slider.horizontalThumbIcon
    Slider.majorTickLength
    Slider.shadow
    Slider.trackWidth
    Slider.verticalThumbIcon
    SliderUI
    Slider.border     
    Slider.focusInsets     
    None of these settings worked.
    I also tried all the settings listed on the following URL :
    http://forums.e-plus.com.au/thread.jsp?forum=3&thread=93
    But they did'nt work either.
    Please help me out??

    Look in the documentation in the styles section.
    Sincerely,
    Michael
    El 15/05/2009, a las 5:26, kRizzl0r <[email protected]> escribió:
    >
    hi there,
    >
    i was wondering why the TextField's selection color in AIR is 
    different from the one in the flashplayer - and if there is a way to 
    change it?
    who chose a grey tone as highlight color, and an even lighter grey 
    when the TextField lost its focus? seems like a strange decision to 
    me..
    >
    cheers
    >

  • Help! How to make background layer colored

    Hi. I have been reading the help section but can't find my
    answer. Hope someone can help me.
    How do you make the background layer of an image COLORED?
    Especially, how do you make the background a colored GRADIENT FILL?
    For example, on layer #1 I have just an abstract design of shapes.
    I want a background layer#2 to be a separate SOLID fill of color,
    or a gradient fill.
    The only way I have figured out how to remotely do this is if I draw
    a rectangle, then stretch it out to edge of "canvas", then fill it w/color
    but the edges never line up perfectly. Isn't there a better way? Thank you so much!

    Thx for your quick reply.
    Really? Wow, well that is good to know then. I used to use
    Illustrator yrs. ago and now I am kind of re-learning it. I just remembered-
    couldn't one create a layer, then select the "paint bucket" tool, pick a color,
    then fill a background that way? Maybe I am thinking of Photoshop....

  • 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?

  • JTabbedPane tab selection colors

    I'm just wondering if there's an easier way to change the colors of the tabs in a JTabbedPane when moving between tabs?? I've tried the UIManager.put() with no luck.
    public void stateChanged(ChangeEvent event)
         if (tabbedPane.getSelectedIndex() == 0)
              tabbedPane.setBackgroundAt(0, panelColor);
              tabbedPane.setBackgroundAt(1, null);
              tabbedPane.setBackgroundAt(2, null);
         else if (tabbedPane.getSelectedIndex() == 1)
              tabbedPane.setBackgroundAt(0, null);
              tabbedPane.setBackgroundAt(1, panelColor);
              tabbedPane.setBackgroundAt(2, null);
         else if (tabbedPane.getSelectedIndex() == 2)
              tabbedPane.setBackgroundAt(0, null);
              tabbedPane.setBackgroundAt(1, null);
              tabbedPane.setBackgroundAt(2, panelColor);

    Try something like this:
    public void stateChanged(ChangeEvent e)
         for (int i = 0; i < tabbedPane.getTabCount(); i++)
              tabbedPane.setBackgroundAt(i, Color.yellow);
              tabbedPane.setForegroundAt(i, Color.redl);
         int selected = tabbedPane.getSelectedIndex();
         tabbedPane.setBackgroundAt( selected, Color.blue );
         tabbedPane.setForegroundAt( selected, Color.green );
    }Does this code work for you?
    When I try this code the setForegroundAt() method works.
    The setBackgroundAt() method works inside the for loop, but not outside. That is I see tabs with a background of yellow, but the selected tab still shows a background of grey, not blue. Does this happen for you.
    I'm running the Windows LAF on Windows 98 and JDK1.3

  • I have changed my background canvas color... but it hasn't changed. HELP

    I have changed my background canvas color too White through the preferences system... but it hasn't changed. Can anyone help me with this as I'm tearing my hair out!!
    S

    somanna wrote:
    I guess that you should have first done this and can even do it even now:
    Have the entire project selected first; then open your preferences and choose your white background. This should allow your entire work to have a white background.
    That is NOT the way it is supposed to work. The background color preference is global to the application, it does not work on a project by project basis. This preference setting determines what FCP X displays in the Viewer in areas where you have no content (or where the content is transparent) - as in the present case, where the photos do not cover the whole viewer area.
    You can easily confirm this. Open some project with a transparent area, and set the background to say, white.
    You should see white showing through any transparent area (that's what the OP was expecting, and it should happen!).
    Now close this project, open something else. Switch to, say, checkerboard background.
    Open the previous project and see the checkerboard (not white!) background.
    One workaround for the present problem is to place a custom generator behind the content, and set its color to white. But of course this should not have been necessary.

  • Selected Color Not Matching

    I have a solid logo color that I need to match my text to.  I've done this for years but now the color is slightly off.  I select color in the character palette, the colors dialogue comes up, I select the eyedropper and then click on the center of my logo, it is yellow.  When I apply the color it is noticeably more orange.  The same goes for choosing grey in a large area to sample from, the grey I'm trying to apply is darker.
    The same thing is happening in Dreamweaver when sampling a large area for the web pages background so it seems it's an adobe wide thing for me.  I tested it in apple's Pages and the color sample seems to work properly.
    Is there some setting somewhere that changes the color?
    Macbook Pro, 23inch display (calibrated) images are in Pro Photo RGB
    Thanks for any clues.

    try creating a new blank 8-bit sRGB document and run your test in that bit/color space
    my guess is the shift is a mismatch between color spaces/gamuts (so you may also need to CONVERT your logo to sRGB) or at least get them both in the same bit/space — also that you may have some Color Setting to check for Preserving Embedded Profiles and Mismatch behaviors)
    also, when working on this kind of stuff for web, I usually CONVERT to sRGB at the beginning of the process (saving my master file in its original space) to avoid these types of issues
    BTW, i am pretty sure dreamweaver is not color manage
    on a Mac that means tagged/untagged/unmanaged dreamweaver color will shift from Photoshop depending on how close or far your monitor is from sRGB profile
    in Safari that means tagged and untagged sRGB will mismatch...

  • Photshop CS5 paint bucket colors do not match selected color picker colors

    I recently installed CS5 on my laptop after first removing it from my previous machine.
    All licences were validated so no problems there.
    Now when using paint bucket in photoshop, the colors that I select in the color picker are not the colors that result when I use the paint bucket.
    If I create a new black canvas then the colors selected in color picker work with paint bucket.
    But if I attempt to recolor the background in an existing image that I import into photoshop, I get the mismatch with colors when I use paint bucket. My method for selecting colors is the same in each case, I select 'set foreground color' and set the color using html values entry at the bottom of the panel.
    Any help would be gratefully received.
    Brent

    Try changing Image > Mode to RGB – does the Tool work as expected then?
    To quote from the Help:
    Indexed Color mode
    Indexed Color mode produces 8-bit image files with up to 256 colors. When converting to indexed color, Photoshop builds a color lookup table (CLUT), which stores and indexes the colors in the image. If a color in the original image does not appear in the table, the program chooses the closest one or uses dithering to simulate the color using available colors.
    Although its palette of colors is limited, indexed color can reduce file size yet maintain the visual quality needed for multimedia presentations, web pages, and the like. Limited editing is available in this mode. For extensive editing, you should convert temporarily to RGB mode. Indexed color files can be saved in Photoshop, BMP, DICOM (Digital Imaging and Communications in Medicine), GIF, Photoshop EPS, Large Document Format (PSB), PCX, Photoshop PDF, Photoshop Raw, Photoshop 2.0, PICT, PNG, Targa®, or TIFF formats.

  • Getting system selection colors

    Hi,
    I am trying to implement the TreeCellRenderer interface. In doing that, I need to take care of the condition when a node is selected by the user, by changing the background and foreground colors of the node.
    Can somebody tell me how to get the default system selection colors?
    In List Renderers, this can be done by calling the getSelectionBackground () method.
    However, no such method exists for JTrees.
    Any ideas?
    ~Y

    Color c = UIManager.getColor("Tree.selectionBackground");
    The tree color keys are these:
    Tree.background
    Tree.foreground
    Tree.selectionBackground
    Tree.selectionBorderColor
    Tree.selectionForeground
    UIDefaults d = UIManager.getDefaults();
    that gets a hashtable (UIDefaults extends Hashtable) so you could use that to get a set of keys and create a list of keys for the L&F you are using. Most key names are pretty obvious what type they are (colors, fonts, etc.)

  • Background Text Color

    I have a problem with background text, particularly in yahoo, but other pages as well. The background color is a light, very light grey. I often have to highlight, or copy and past to be able to read.
    Is there a way to change these background text colors???
    Thanks

    Hi,
    Open System Preferences / Universal Accesss - Seeing.
    See if you have the Display set as "Whtie on black".
    Or, if the "User grayscale" box is selected, deselect that.
    Or, try move the Reduce or Increase contrast slider.
    Carolyn
    Message was edited by: Carolyn Samit

Maybe you are looking for

  • Can´t add files to Mediathek? Limit at 24950???

    Hello, I can´t add Songs to the Library. The is no Message or error, I can rip CDs and they will be copied as MP3 into the regular Folders on the computer, but they won´t be added to the library. I have all rights for the Songs, and there is enough S

  • Text sound and no text

    Since I got the 2.1 upgrade, I keep getting the text message noise and no text message. I am getting most text messages, but where are the other ones going, and why aren't they showing up!?

  • Can not open safari because it has been close unexpectedly.....

    I can't open safari because a window come up saying that it has been close unexpectedly, I can't open safari because a window come up saying that it has been close unexpectedly

  • XML Template could not find error when submitting for other than English

    Hi All, When I try to submit my custom xml report through SRS window, in NON english language, I get following error "The simultaneous application program could not find an xml template for the program. Check the configuration of the data and informa

  • How can I add a 'Virtual 7354' device?

    We are looking to purchase a PCI-7354 and I noticed that after installing the latest NI-Motion 8.3 that there is no option to add a Virtual 7354 device.  The only options I see are: 7344, 7334, 7358 and 7390.  Can I safely choose the 7358 and integra