Class GradientPanel

    • Field Detail

      • start

        protected Color start
        Gradient start colour
      • end

        protected Color end
        Gradient end color
      • cache

        protected BufferedImage cache
        A pre-rendered gradient in an image
    • Constructor Detail

      • GradientPanel

        public GradientPanel()
    • Method Detail

      • setBackground

        public void setBackground​(Color color)
        Set the background to a single color
        Overrides:
        setBackground in class JComponent
        Parameters:
        color - The color for a solid background
      • setBackground

        public void setBackground​(Color start,
                                  Color end)
        Sets two background colors for a gradient
        Parameters:
        start - Top (first) color
        end - Bottom (final) color
      • paintComponent

        public void paintComponent​(Graphics graphics)
        paints the gradient.
        Overrides:
        paintComponent in class JComponent
        Parameters:
        graphics - The graphics context
      • componentResized

        public void componentResized​(ComponentEvent componentEvent)
        Recalculates the gradient when it's resized
        Specified by:
        componentResized in interface ComponentListener
        Parameters:
        componentEvent - The event object