How do I change the colour of a selected cell in a jTable?

I have a Jtable that displays URL names in one column. There are several problems I'm having. The effect I'm trying to achieve is this:
When the user runs the mouse over the URL name the cursor should change into a hand (similar to what happens in an HTML hyperlink). I'm aware that the Cursor class can set the cursor graphic so i figure that i need a listener of some sort on each cell (so the cursor can change from an arrow to a hand) and also one to indicate when the cursor is not on a cell (so that it can change from a hand back into an arrow). Is this the right track?
Also, I've looked at the DefaultTableCellRenderer class (which, as i understand it, is responsible for how each cell in the jtable is displayed) for a method that will allow me to set the background of a selected cell (or row or column). I require this because each time i select a cell (or row) it becomes highlighted in blue. I would rather it just remained white and changed the cursor to a hand. I know there exists a method for setting the background for an unselected cell but none for a selected cell. Again, I'm not sure if I'm going down the right track with this approach.
Lastly, if the cell has been selected (by a mouse click) the font of the writing in the cell (i.e. The name of the URL) should change. This shouldn't be too much of a problem I think.
I do not expect anyone to provide code to do all of this but some general pointers would be extremely helpful as I do not know if I'm thinking on the right track for any of this. Having some (limited) experience with Swing I doubt there is a simple way to do this but I can only hope!
Thanks.
Chris

http://www2.gol.com/users/tame/swing/examples/SwingExamples.html
there you can find some examples with CellRenderer's and so on ...
have fun

Similar Messages

  • How can I change the colour of an iCal calender on the iPhone?

    I have two iCal calendars on my iPhone that sync to google. It works fine with push but both of hem has the same colour. That makes it hard to see the diference.
    How can I change the colour?
    I am syncing to outlook so I don't have iCal on the statonary.

    I looked into this before, and at the moment there is little you can do to customize the inputrender tag, short of subclassing it and adding the functionality you require

  • My itunes screen is black and i cant see the writing how do i change the colour

    My itunes screen is black when im trying to find music - how do i change the colour as i cant see the writing

    With that one, perhaps try Drgoo's suggestion from the following post:
    Re: Itunes Store - ALL Text Black/Cant See Anything

  • How do I change the COLOUR SPACE in elements 11 editor ?

    How do I change the COLOUR SPACE in elements 11 editor ?

    I believe you would do this with LUTs applied to the clips directly.

  • How do I change the background of a single cell or a row in a table?

    How do I change the background of a single cell or a row in a
    table? I doesn't seem to be letting me do that.

    Are you using the latest DW? If so, then it isn't letting you
    because
    bgcolor is deprecated and shouldn't be used.
    The correct way is to use css to define the background of a
    cell
    CSS:
    .blackcell {background-color: black;}
    HTML:
    <td class="blackcell">whatever in the cell</td>
    Nadia
    Adobe® Community Expert : Dreamweaver
    CSS Templates |Tutorials |SEO Articles
    http://www.DreamweaverResources.com
    ~ Template Customization ~
    http://www.csstemplates.com.au
    Spry Widget Examples
    http://www.dreamweaverresources.com/spry-widgets/
    "dm25" <[email protected]> wrote in message
    news:f4jr5h$luu$[email protected]..
    > for some reason that doesn't always work. When I click
    inside a cell, it
    > doesn't give me an option to change the background
    color.

  • To change the font of a selected row in a Jtable

    Hello,
    Is it possible to change the font of a selected row in a jtable?
    i.e. if all the table is set to a bold font, how would you change the font of the row selected to a normal (not bold) font?
    thank you.

    String will be left justified
    Integer will be right justified
    Date will be a simple date without the time.
    As it will with this renderer.Only if your custom renderer duplicates the code
    found in each of the above renderers. This is a waste
    of time to duplicate code. The idea is to reuse code
    not duplicate and debug again.
    No, no, no there will be NO duplicated code.
    A single renderer class can handle all types ofdata.
    Sure you can fit a square peg into a round hole if
    you work hard enough. Why does the JDK come with
    separate renderers for Date, Integer, Double, Icon,
    Boolean? So that, by default the rendering for common classes is done correctly.
    Because its a better design then having code
    with a bunch of "instanceof" checks and nested
    if...else code.This is only required for customization BEYOND what the default renderers provide
    >
    And you would only have to use instanceof checkswhen you required custom
    rendering for a particular classAgreed, but as soon as you do require custom
    renderering you need to customize your renderer.
    which you would also have to do with theprepareRenderer calls too
    Not true. The code is the same whether you treat
    every cell as a String or whether you use a custom
    renderer for every cell. Here is the code to make the
    text of the selected line(s) bold:
    public Component prepareRenderer(TableCellRenderer
    renderer, int row, int column)
    Component c = super.prepareRenderer(renderer, row,
    , column);
         if (isRowSelected(row))
              c.setFont( c.getFont().deriveFont(Font.BOLD) );
         return c;
    }It will work for any renderer used by the table since
    the prepareRenderer(...) method returns a Component.
    There is no need to do any kind of "instanceof"
    checking. It doesn't matter whether the cell is
    renderered with the "Object" renderer or the
    "Integer" renderer.
    If the user wants to treat all columns as Strings or
    treat individual columns as String, Integer, Data...,
    then they only need to override the getColumnClass()
    method. There is no change to the prepareRenderer()
    code.
    Have you actually tried the code to see how simple it
    is?
    I've posted my code. Why don't you post your solution
    that will allow the user to bold the text of a Date,
    Integer, and String data in separate column and then
    let the poster decide.Well, I don't see a compilable, runnable demo anywhere in this thread. So here's one
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.*;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Arrays;
    import java.util.Date;
    import java.util.Vector;
    public class TableRendererDemo extends JFrame{
        String[] headers = {"String","Integer","Float","Boolean","Date"};
        private JTable table;
        public TableRendererDemo() {
            buildGUI();
        private void buildGUI() {
            JPanel mainPanel = (JPanel) getContentPane();
            mainPanel.setLayout(new BorderLayout());
            Vector headerVector = new Vector(Arrays.asList(headers));
             Vector data = createDataVector();
            DefaultTableModel tableModel = new DefaultTableModel(data, headerVector){
                public Class getColumnClass(int columnIndex) {
                    return getValueAt(0,columnIndex).getClass();
            table = new JTable(tableModel);
    //        table.setDefaultRenderer(Object.class, new MyTableCellRenderer());
            table.setDefaultRenderer(String.class, new MyTableCellRenderer());
            table.setDefaultRenderer(Integer.class, new MyTableCellRenderer());
            table.setDefaultRenderer(Float.class, new MyTableCellRenderer());
            table.setDefaultRenderer(Date.class, new MyTableCellRenderer());
            JScrollPane jsp = new JScrollPane(table);
            mainPanel.add(jsp, BorderLayout.CENTER);
            pack();
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        private Vector createDataVector(){
            Vector dataVector = new Vector();
            for ( int i = 0 ; i < 10; i++){
                Vector rowVector = new Vector();
                rowVector.add(new String("String "+i));
                rowVector.add(new Integer(i));
                rowVector.add(new Float(1.23));
                rowVector.add( (i % 2 == 0 ? Boolean.TRUE : Boolean.FALSE));
                rowVector.add(new Date());
                dataVector.add(rowVector);
            return dataVector;
        public static void main(String[] args) {
            Runnable runnable = new Runnable() {
                public void run() {
                    TableRendererDemo tableRendererDemo = new TableRendererDemo();
                    tableRendererDemo.setVisible(true);
            SwingUtilities.invokeLater(runnable);
        class MyTableCellRenderer extends DefaultTableCellRenderer{
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                 super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                if ( isSelected){
                    setFont(getFont().deriveFont(Font.BOLD));
                else{
                    setFont(getFont().deriveFont(Font.PLAIN));
                if ( value instanceof Date){
                    SimpleDateFormat formatter =(SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.MEDIUM);
                    setText(formatter.format((Date)value));
                if(value instanceof Number){
                   setText(((Number)value).toString());
                return this;
    }Hardly a "bunch of instanceof or nested loops. I only used the Date instanceof to allow date format to be specified/ modified. If it was left out the Date column would be "18 Apr 2005" ( DateFormat.MEDIUM, which is default).
    Cheers
    DB

  • How do I change the colour of text in a cell in a JTable?

    I am trying to change the color of the text in a single cell in a JTable. I have tried not adding a cell renderer and it changes the colour of text in all cells.
    I have tried adding a cell renderer to the table and it does the same ie all cells text colour changes.
    I am able to add a cell renderer to a column and it changes all the cells in the column.
    I cannot figure out how to change just one single cell's text colour without effecting the other cells.

    Ok, so if i create my own cell renderer do I set it as the default renderer for the whole table i.e.
    table.setDefaultRenderer(MyCellRenderer, renderer);
    Does this set one cell renderer for the whole table or is there an individual one for each cell?

  • How do I change the colour of a PS frame?

    I am creating christmas cards and adding photos of my kids onto christmas backgrounds. I am dragging frames from the right hand side but want to change the colour of these frames - can someone please tell me how to do that?
    I've worked out how to do it by clicking on the black/white circle and using the hue/saturation but when I go to do that with the frame on the new background, the colour of the background changes instead of the frame. I need to change the frames colour while on the background to get an exact match to what I want (does that make sense???)
    Is there an easier way to create a frame for the photos? I also want to create a text box / frame (with the christmas message) with a solid colour background (different to the main background) can anybody tell me how to do that?
    An example of what I am trying to do is here http://www.invitations2impress.com/christmas-cards-gift-tags
    Thanks in advance )

    In a nutshell, you have to simplify the frame layer and erase the interior.
    Here are the steps:
    Create your background.
    Add a new layer:
    Drag the frame you want to use onto the editing surface.  The frame will come in on its own layer:
    Simplify that frame layer:
    Choose the Magic Wand Tool and give it these settings:
    Click on the interior gray area of the frame with the Magic Wand to select it, and hit your Delete key:
    Switch to the Eraser Tool and erase the stuff that's left in the middle:
    Select the empty layer (Layer 1 in this example) and use File...Place to place your image on it.  The layer name will change to the name of the image.  Adjust the size and placement of the image.  Your layers will now look like this:
    With the frame layer selected, add a Hue/Saturation adjustment layer, making sure to "clip" it to the frame layer.  Adjust the sliders to suit:
    The final result:
    Ken
    P.S.,  Nothing says "Christmas" like laundry and red leopard fur! 

  • How to I change the colour (or hightlight) some of the bars in a bar chart in Keynote?

    I am using Keynote 6.2.2.  I have prepared a chart which displays the quarterly income (as a points on a line) and expenditure (as bars) for the past 3 years.  I wish to highlight the Q1 expenditure bars for comparison reasons.  At the moment all the bars are coloured red (and the income lines, blue).  How can I either change the colours of just the Q1 expenditure bars for each year?

    You need to change to;   plot columns:
    select the chart
    click the Edit Chart Data button
    click the plot columns button (arrowed)
    select the chart then select the individual bars to be changed:

  • How do I change the colour and keep the gradient?

    I've downloaded an EPS from Shutterstock with a series of icons that look like buttons and would like to change the colour breakdown, but keep the shading/ button 'look'.
    Please can you show me how? When I try to select a different colour breakdown of blue it turns grey and solid.

    Thank you very much for your suggestion. Unfortunatly I have not managed to get that to work either - see above, when trying the change the path colour to another blue (in one place - the highlighted row only) it comes up grey in multiple places (see group and mesh changed above).

  • How can I change the colour of the chart in the new Keynote?

    In the last version I simply choose the color (for example metallic and choose the one I want for each bar). In the new version I can choose only the category of the colour but how can I manage the colour of a specific bar or pice of pie?
    thanks for your help

    I find the solution! Just click on the section you want to change color, go to style and click the colour you want.

  • How do you change the colour of the "colour boxes" in themes?

    Creating a book in Aperture the various "Themes" offer you different layouts.  When you are in a Theme - is there a way to change the colours of the background boxes (Not page colour) - I have searched everywhere to see how to do this and a simple thing like this seems like it is not possible.  Yes you could make a photo of the correct colour you want and drag it in but surely there is a simple way of changing the colour of these theme boxes. 
    The theme I am using is Special Occasion and I want to darken the lightblue boxes behind the text. 
    Would appreciate anyone out there who could advise on this please, thank you in advance.
    Richard
    Apperture 3.4.3
    iMac 21.5 OS 10.7.5
    iMac 27 OS 10.6.8 (the best)

    Richard,
    there is no built-in option to change the color boxes. You can only change them by patching the Resorces in the Aperture application bundle, and that is risky.
    The color of the background boxes is set in the property list (for the Extra Large Book):
    /Applications/Aperture.app/Contents/Resources/Book Themes/Special Occasion/ExtraLarge/Graphics/BlueRect.plist
    The current value is:
    backgroundColor {224, 241, 238, 100}
    To try what happens, when this value is changed, I edited it to {100, 200, 255, 100}
    You will not really want to patch your Aperture application bundle
    What you might try, would be to copy the "Special Occasion" subfolder of the Book Themes and to create your own custom theme from this and install it in your user library
    ~/Library/Application Support/Aperture/Book Themes/
    -- Léonie

  • How Can I change the colour in title bar of Window in Form 9i

    Hello
    All,
    I want to change the colour of title bar in window ?
    how can I ?
    From
    Chriag Patel

    Chirag,
    this is not in a scope of control for Forms and instead determined by the look and feel.
    Frank

  • How to permanently change the colour of a button

    I am using an action to change the colour of a button.  This works but the colour changes for only about a second and then reverts to the original colour.  How can I make the colour change permanently?

    Hi RajeevAdobe,
    Sorry I didn't give enough detail. What I want to do is have a page with buttons that link to a number of tasks. At the start only task 1 button will be enabled and it will be a different colour from the rest.  Once they get task 1 right they go back to the first page and task 2 button will be enabled and the colour changed. The way I am doing this is if they get task 1 right I set a variable task1Success as yes then take them back to the first page which I am calling the "wall".
    So when they first enter the "wall":
    Then user goes to task 1.
    Using:
    Then when they get back to the "wall" I check if the task1Success variable has been changed to yes and if it has I enable the task 2 button and change it's colour using Apply Effect - Advanced - Colour Effect - Advanced.
    This all works OK and when the wall first loads it looks like below but the colour of task2 button only changes for about a second I want it to change permanently.
    Thanks for your help,
    Chris

  • How can I change the colour of the tools?

    I want to change the colour of the blue box next to the word diabc. The blue field is a tool with you can change the text. I know how to change one field at a time but I want to change the standard settigns, so that I don't have to change it field for field. I can't find it anywhere. I have found some information about changing the tool bars, but you can't change this tool I use. Only others.
    Who can help me? I have Adobe Acrobat 9 pro extended. I use the Dutch version, so some things may have a different name.
    I have included some pictures.
    If you have any questions, just ask. 

    Thanks for your help so far.
    I hope you can see it now. It's a bit difficult to make a picture from my print screen, because I don't have the right programs at my computer at work.
    The menu is in Dutch. But I don't have so many options as you have. If I go to 'eigenschappen' (in English properties) I get this menu. In this menu you can change the colour, but Adobe doesnt' remember this, so you have to change it every time. And that's quite a lot of work if you want to do this. Because I have to review a document of 40 pages.

Maybe you are looking for

  • "Sorry, a serious error has occurred that requires Premiere Elements to be shut down. We will attemp

    I have been getting this message just a few nights ago after working on a project. Premiere was working at first for a few days but then this happened. Now everytime I try to activate the program it displays "Sorry, a serious error has occurred that

  • I have a 2010 Cadillac CTS that no longer works w/my iPhone 4 after iOS7 Upgrade.

    I have a 2010 Cadillac CTS that no longer works w/my iPhone 4 after iOS7 Upgrade.  Any suggestions?  It worked well before the upgrade.

  • Corrective actions setup problem

    Hi guys! I have problem with setup corrective action for listener avaliability when status is down and action doesnt work at all. I have create template Listener_stuff with metric trasholds for Response Time (msec) and Status is down. Other details f

  • InDesign file not opening on Mac

    One of my indesign file crashed on couple of occasion and now it is failing to open. I deleted InDesign prefs files but that doesn't seem to work. Is there some way I can manage to open the file? OS X 10.8.4 InDesign CC, CS5 and CS6

  • Google image search being cut out?

    Ever since Google's image search has this new format, whenever I search up something a second time, it only shows two rows of images, instead of full screen. I will show you what I mean in a picture. Does this happen to anyone else? It happens on bot