4 Replies Latest reply: Oct 7, 2004 1:36 PM by camickr RSS

    Gradient selected row in JTable

    807587
      Hello,

      how is it possible to make a gradient background color for the selected row in a JTable?
      Now I use plain color but I want a gradient. Is it possible?

      Thanks!
        • 1. Re: Gradient selected row in JTable
          807587
          First thing that comes to mind:
          This would work for a single cell, but would repeat the graident pattern for each cell in a selected row.

          1. Create a custom component that can rend a gradient back ground. I recomend subclassing JLabel and overiding printComponent(Graphics g).

          2. Create a cellRenderer that returns a normal JLabel for a non selected row and your custom JLabel for a selected row.



          • 2. Re: Gradient selected row in JTable
            807587
            Sure! Subclass DefaultTableCellRenderer or roll your own TableCellRenderer. Overirde paintComponent or paint
            and use GradientPaint...
            • 3. Re: Gradient selected row in JTable
              807587
              1. Create a custom component that can rend a gradient
              back ground. I recomend subclassing JLabel and
              overiding printComponent(Graphics g).
              Make that paintComponent. Woops!
              • 4. Re: Gradient selected row in JTable
                camickr
                how is it possible to make a gradient background color for the selected row in a JTable?
                If you want a gradient for individual cells then you would create a custom renderer as advised above.

                If you want a gradient that changes for the entire row from the first to last column then you would need to make all your renderers non-opaque and then add custom painting in the JTable paintComponent(...) method.