Results 1 to 9 of 9
  1. #1
    pink123 is offline Member
    Join Date
    Feb 2011
    Posts
    84
    Rep Power
    0

    Default Not able to select a column

    Hi,

    I have a jtable with 7 columns.I have applied user defined cell renderer to column 7th to disable it based on certain condition.
    When I make a selection in jtable all the columns for any particular row are selected (color changes to blue) except 7th column.
    Is it because of the cell renderer or I am missing something??

    Thanks,

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,037
    Rep Power
    10

    Default

    If you want help, you should provide an SSCCE demonstrating what your cell renderer is doing. That doesn't mean you should post your whole program.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    pink123 is offline Member
    Join Date
    Feb 2011
    Posts
    84
    Rep Power
    0

    Default

    my cell renderer does the following


    MyClass extends JCheckBox implements TableCellRenderer ,UIResource

    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus, int row, int column)
    {
    if cell is not editable
    {
    change the background to grey
    }
    else
    {
    setBackground(table.getBackground());
    setForeground(table.getForeground());
    }
    return this;
    }



    Thanks,

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,037
    Rep Power
    10

    Default

    Okay, so in that renderer, where do you set the background based on whether or not the cell is selected?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    pink123 is offline Member
    Join Date
    Feb 2011
    Posts
    84
    Rep Power
    0

    Default

    i have to grey out column 7 based on some condition ,thats working fine but
    when I select a row from the jtable ,all columns except column 7 get selected
    .Do I have to add something in the renderer?
    My jtable is having the following statement ,but column 7 is not selected

    table.getSelectionModel().setSelectionMode(ListSel ectionModel.SINGLE_SELECTION);

    Do I have to add something like the above statement in my renderer.

    Thanks,

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,037
    Rep Power
    10

    Default

    You have to set the background based on whether the cell is selected.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    pink123 is offline Member
    Join Date
    Feb 2011
    Posts
    84
    Rep Power
    0

    Default

    No I dont have to change the background on the basis if cell is selected or not.
    I have to change the backbround based on some other conditions.

    This is a different thing,column 7 doesnt show blue color and all other columns show when i click on any row.

    Thanks,

  8. #8
    pink123 is offline Member
    Join Date
    Feb 2011
    Posts
    84
    Rep Power
    0

    Default

    Thanks for your help.
    It worked with

    if (isSelected) {
    setBackground(table.getSelectionBackground());
    setForeground(table.getSelectionForeground());
    } else {
    setBackground(table.getBackground());
    setForeground(table.getForeground());

    Thanks,

  9. #9
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,037
    Rep Power
    10

    Default

    I'm glad you got it sorted, but for future reference, responding to advice with statements like "No I don't... this is a different thing" is one sure-fire way to make sure people don't help you in the future.. especially when the advice was spot-on in the first place. But even if it's not, a little gratitude goes a long way. Do with that what you will.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 11
    Last Post: 10-21-2014, 05:46 AM
  2. insert row and column and delete row and column
    By daredavil82 in forum New To Java
    Replies: 13
    Last Post: 09-22-2011, 07:10 PM
  3. Replies: 1
    Last Post: 07-06-2010, 05:50 PM
  4. Replies: 2
    Last Post: 03-05-2009, 03:10 PM
  5. How to retain value in struts 2 using <s:select></s:select> tag
    By SaiPrasad@Sella in forum Web Frameworks
    Replies: 0
    Last Post: 02-09-2009, 08:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •