CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 1999
    Posts
    47

    Color Changing, JTable

    Hello

    I Created a Frame. On TOp of the Frame I had a Button "Change". Under That I had a Table with 10 row's with White Back Ground ( default renderer).

    CASE1>>IF I Press Change button,

    1)First 5 rows Should display with RED Color(i.e red BackGround)
    2) Next 3 rows should display with Blue Color(i.e Blue BackGround)
    3) Next 2 rows should display with Green Color(i.e Green BackGround)


    CASE2>>If Again I press Change Button,

    Again I should Get Original State. I.e With White BackGround.
    (Default renderer)

    How TO Switch case1 to case 2 or case2 to case1..Like above.......

    Please give an example........

    REGARDS
    CHANDRA


  2. #2
    Join Date
    May 1999
    Location
    Pune, MH, India.
    Posts
    453

    Re: Color Changing, JTable

    U can create a custom renderer. This renderer will maintain state 'DEFAULT', 'COLORED'.

    Now the renderer be probably 'JLabel' only. The only thing is u will check the state and then decide whether to color the background. If no, just do 'setOpaque(false)'. If yes, check the row index and give the background color accordingly.

    Now to change the state of renderer...
    1. U will have a function to the renderer class say 'toggleState' This will toggle the state.
    2. In the handler of change button, u will call this method. (For this u will need to store the object of the renderer class in the class having handler for the button, or u can retrieve the renderer and typecast it)

    Does this answer ur question?

    - UnicMan
    http://members.tripod.com/unicman

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured