Class JXPanel

    • Nested Class Summary

      • Nested classes/interfaces inherited from class javax.swing.JPanel

        javax.swing.JPanel.AccessibleJPanel
      • Nested classes/interfaces inherited from class javax.swing.JComponent

        javax.swing.JComponent.AccessibleJComponent
      • Nested classes/interfaces inherited from class java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private float alpha
      The alpha level for this component.
      private Painter backgroundPainter
      Specifies the Painter to use for painting the background of this panel.
      (package private) boolean fakeTransparent  
      private boolean inheritAlpha
      Indicates whether this component should inherit its parent alpha value
      private static java.util.logging.Logger LOG  
      private float oldAlpha  
      private boolean oldOpaque
      If the old alpha value was 1.0, I keep track of the opaque setting because a translucent component is not opaque, but I want to be able to restore opacity to its default setting if the alpha is 1.0.
      private boolean paintBorderInsets  
      private java.beans.PropertyChangeListener painterChangeListener
      The listener installed on the current backgroundPainter, if any.
      private ScrollableSizeHint scrollableHeightHint  
      private ScrollableSizeHint scrollableWidthHint  
      • Fields inherited from class javax.swing.JComponent

        listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
      • Fields inherited from class java.awt.Component

        accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
      • Fields inherited from interface java.awt.image.ImageObserver

        ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
    • Constructor Summary

      Constructors 
      Constructor Description
      JXPanel()
      Creates a new JXPanel with a double buffer and a flow layout.
      JXPanel​(boolean isDoubleBuffered)
      Creates a new JXPanel with FlowLayout and the specified buffering strategy.
      JXPanel​(java.awt.LayoutManager layout)
      Create a new buffered JXPanel with the specified layout manager
      JXPanel​(java.awt.LayoutManager layout, boolean isDoubleBuffered)
      Creates a new JXPanel with the specified layout manager and buffering strategy.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      float getAlpha()
      Get the current alpha value.
      Painter getBackgroundPainter()
      Returns the current background painter.
      float getEffectiveAlpha()
      Unlike other properties, alpha can be set on a component, or on one of its parents.
      protected java.beans.PropertyChangeListener getPainterChangeListener()  
      java.awt.Dimension getPreferredScrollableViewportSize()
      int getScrollableBlockIncrement​(java.awt.Rectangle visibleRect, int orientation, int direction)
      protected ScrollableSizeHint getScrollableHeightHint()  
      boolean getScrollableTracksViewportHeight()
      boolean getScrollableTracksViewportWidth()
      int getScrollableUnitIncrement​(java.awt.Rectangle visibleRect, int orientation, int direction)
      protected ScrollableSizeHint getScrollableWidthHint()  
      (package private) void installRepaintManager()  
      protected boolean isAlpha()
      Returns whether or not the container hierarchy below is transparent.
      boolean isInheritAlpha()
      Returns the state of the panel with respect to inheriting alpha values.
      boolean isOpaque()  
      protected boolean isOpaquePatch()  
      boolean isPaintBorderInsets()
      Returns true if the background painter should paint where the border is or false if it should only paint inside the border.
      protected boolean isPaintingBackground()
      Returns whether or not the background should be painted.
      protected boolean isPaintingOrigin()  
      protected boolean isPatch()  
      protected boolean isTransparentBackground()
      Returns whether or not the background is transparent.
      void paint​(java.awt.Graphics g)
      Overridden paint method to take into account the alpha setting.
      protected void paintComponent​(java.awt.Graphics g)
      Overridden to provide Painter support.
      protected void paintComponentPatch​(java.awt.Graphics g)  
      void setAlpha​(float alpha)
      Set the alpha transparency level for this component.
      private void setAlphaPatch​(float alpha)
      experimental version: doesn't tweak opaque called if isPatch
      void setBackgroundPainter​(Painter p)
      Sets a Painter to use to paint the background of this JXPanel.
      void setInheritAlpha​(boolean val)
      Determines if the effective alpha of this component should include the alpha of ancestors.
      void setOpaque​(boolean opaque)
      protected void setOpaquePatch​(boolean opaque)  
      void setPaintBorderInsets​(boolean paintBorderInsets)
      Sets the paintBorderInsets property.
      void setScrollableHeightHint​(ScrollableSizeHint hint)
      Sets the vertical sizing hint.
      void setScrollableTracksViewportHeight​(boolean scrollableTracksViewportHeight)
      Sets the vertical size tracking to either ScrollableSizeTrack.FIT or NONE, if the boolean parameter is true or false, respectively.
      void setScrollableTracksViewportWidth​(boolean scrollableTracksViewportWidth)
      Sets the horizontal size tracking to either ScrollableSizeTrack.FIT or NONE, if the boolean parameter is true or false, respectively.
      void setScrollableWidthHint​(ScrollableSizeHint hint)
      Sets the horizontal sizing hint.
      (package private) void uninstallRepaintManager()  
      • Methods inherited from class javax.swing.JPanel

        getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
      • Methods inherited from class javax.swing.JComponent

        addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
      • Methods inherited from class java.awt.Container

        add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • alpha

        private volatile float alpha
        The alpha level for this component.
      • oldOpaque

        private boolean oldOpaque
        If the old alpha value was 1.0, I keep track of the opaque setting because a translucent component is not opaque, but I want to be able to restore opacity to its default setting if the alpha is 1.0. Honestly, I don't know if this is necessary or not, but it sounded good on paper :)

        TODO: Check whether this variable is necessary or not

      • oldAlpha

        private float oldAlpha
      • inheritAlpha

        private boolean inheritAlpha
        Indicates whether this component should inherit its parent alpha value
      • backgroundPainter

        private Painter backgroundPainter
        Specifies the Painter to use for painting the background of this panel. If no painter is specified, the normal painting routine for JPanel is called. Old behavior is also honored for the time being if no backgroundPainter is specified
      • paintBorderInsets

        private boolean paintBorderInsets
      • painterChangeListener

        private java.beans.PropertyChangeListener painterChangeListener
        The listener installed on the current backgroundPainter, if any.
      • fakeTransparent

        boolean fakeTransparent
      • LOG

        private static final java.util.logging.Logger LOG
    • Constructor Detail

      • JXPanel

        public JXPanel()
        Creates a new JXPanel with a double buffer and a flow layout.
      • JXPanel

        public JXPanel​(boolean isDoubleBuffered)
        Creates a new JXPanel with FlowLayout and the specified buffering strategy. If isDoubleBuffered is true, the JXPanel will use a double buffer.
        Parameters:
        isDoubleBuffered - a boolean, true for double-buffering, which uses additional memory space to achieve fast, flicker-free updates
      • JXPanel

        public JXPanel​(java.awt.LayoutManager layout)
        Create a new buffered JXPanel with the specified layout manager
        Parameters:
        layout - the LayoutManager to use
      • JXPanel

        public JXPanel​(java.awt.LayoutManager layout,
                       boolean isDoubleBuffered)
        Creates a new JXPanel with the specified layout manager and buffering strategy.
        Parameters:
        layout - the LayoutManager to use
        isDoubleBuffered - a boolean, true for double-buffering, which uses additional memory space to achieve fast, flicker-free updates
    • Method Detail

      • setOpaque

        public void setOpaque​(boolean opaque)

        Setting the component to be opaque will reset the alpha setting to 1f (full opaqueness). Setting the component to be non-opaque will restore the previous alpha transparency. If the component is non-opaque with a fully-opaque alpha value (1f), the behavior should be the same as as a JPanel that is non-opaque.

        Overrides:
        setOpaque in class javax.swing.JComponent
      • isOpaque

        public boolean isOpaque()
        Overrides:
        isOpaque in class javax.swing.JComponent
      • getAlpha

        public float getAlpha()
        Get the current alpha value.
        Specified by:
        getAlpha in interface AlphaPaintable
        Returns:
        the alpha translucency level for this component. This will be a value between 0 and 1, inclusive.
      • setAlpha

        public void setAlpha​(float alpha)
        Set the alpha transparency level for this component. This automatically causes a repaint of the component.
        Specified by:
        setAlpha in interface AlphaPaintable
        Parameters:
        alpha - must be a value between 0 and 1 inclusive
      • setAlphaPatch

        private void setAlphaPatch​(float alpha)
        experimental version: doesn't tweak opaque called if isPatch
        Parameters:
        alpha -
      • installRepaintManager

        void installRepaintManager()
      • uninstallRepaintManager

        void uninstallRepaintManager()
      • getEffectiveAlpha

        public float getEffectiveAlpha()
        Unlike other properties, alpha can be set on a component, or on one of its parents. If the alpha of a parent component is .4, and the alpha on this component is .5, effectively the alpha for this component is .4 because the lowest alpha in the hierarchy "wins."
        Specified by:
        getEffectiveAlpha in interface AlphaPaintable
        Returns:
        the lowest alpha value in the hierarchy
      • setScrollableWidthHint

        public final void setScrollableWidthHint​(ScrollableSizeHint hint)
        Sets the horizontal sizing hint. The hint is used by the Scrollable implementation to service the getScrollableTracksWidth.
        Parameters:
        hint - the horizontal sizing hint, must not be null and must be vertical.
        Throws:
        java.lang.NullPointerException - if null
        See Also:
        setScrollableHeightHint(ScrollableSizeHint), ScrollableSizeHint
      • setScrollableHeightHint

        public final void setScrollableHeightHint​(ScrollableSizeHint hint)
        Sets the vertical sizing hint. The hint is used by the Scrollable implementation to service the getScrollableTracksHeight.
        Parameters:
        hint - the vertical sizing hint, must not be null and must be vertical.
        Throws:
        java.lang.NullPointerException - if null
        See Also:
        setScrollableWidthHint(ScrollableSizeHint), ScrollableSizeHint
      • getScrollableTracksViewportHeight

        public boolean getScrollableTracksViewportHeight()
        Specified by:
        getScrollableTracksViewportHeight in interface javax.swing.Scrollable
      • getScrollableTracksViewportWidth

        public boolean getScrollableTracksViewportWidth()
        Specified by:
        getScrollableTracksViewportWidth in interface javax.swing.Scrollable
      • getPreferredScrollableViewportSize

        public java.awt.Dimension getPreferredScrollableViewportSize()
        Specified by:
        getPreferredScrollableViewportSize in interface javax.swing.Scrollable
      • getScrollableBlockIncrement

        public int getScrollableBlockIncrement​(java.awt.Rectangle visibleRect,
                                               int orientation,
                                               int direction)
        Specified by:
        getScrollableBlockIncrement in interface javax.swing.Scrollable
      • getScrollableUnitIncrement

        public int getScrollableUnitIncrement​(java.awt.Rectangle visibleRect,
                                              int orientation,
                                              int direction)
        Specified by:
        getScrollableUnitIncrement in interface javax.swing.Scrollable
      • setScrollableTracksViewportHeight

        public void setScrollableTracksViewportHeight​(boolean scrollableTracksViewportHeight)
        Sets the vertical size tracking to either ScrollableSizeTrack.FIT or NONE, if the boolean parameter is true or false, respectively.

        NOTE: this method is kept for backward compatibility only, for full control use setScrollableHeightHint.

        Parameters:
        scrollableTracksViewportHeight - The scrollableTracksViewportHeight to set.
        See Also:
        setScrollableHeightHint(ScrollableSizeHint)
      • setScrollableTracksViewportWidth

        public void setScrollableTracksViewportWidth​(boolean scrollableTracksViewportWidth)
        Sets the horizontal size tracking to either ScrollableSizeTrack.FIT or NONE, if the boolean parameter is true or false, respectively.

        NOTE: this method is kept for backward compatibility only, for full control use setScrollableWidthHint.

        Parameters:
        scrollableTracksViewportWidth - The scrollableTracksViewportWidth to set.
        See Also:
        setScrollableWidthHint(ScrollableSizeHint)
      • getPainterChangeListener

        protected java.beans.PropertyChangeListener getPainterChangeListener()
        Returns:
        a listener for painter change events
      • isPaintBorderInsets

        public boolean isPaintBorderInsets()
        Returns true if the background painter should paint where the border is or false if it should only paint inside the border. This property is true by default. This property affects the width, height, and initial transform passed to the background painter.
        Specified by:
        isPaintBorderInsets in interface BackgroundPaintable
        Returns:
        true to paint under the border; false otherwise
      • setPaintBorderInsets

        public void setPaintBorderInsets​(boolean paintBorderInsets)
        Sets the paintBorderInsets property. Set to true if the background painter should paint where the border is or false if it should only paint inside the border. This property is true by default. This property affects the width, height, and initial transform passed to the background painter. This is a bound property.
        Specified by:
        setPaintBorderInsets in interface BackgroundPaintable
      • isPaintingOrigin

        protected boolean isPaintingOrigin()
        Overrides:
        isPaintingOrigin in class javax.swing.JComponent
      • paint

        public void paint​(java.awt.Graphics g)
        Overridden paint method to take into account the alpha setting.
        Overrides:
        paint in class javax.swing.JComponent
        Parameters:
        g - the Graphics context in which to paint
      • paintComponent

        protected void paintComponent​(java.awt.Graphics g)
        Overridden to provide Painter support. It will call backgroundPainter.paint() if it is not null, else it will call super.paintComponent().
        Overrides:
        paintComponent in class javax.swing.JComponent
        Parameters:
        g - the Graphics context in which to paint
      • isPatch

        protected boolean isPatch()
      • paintComponentPatch

        protected void paintComponentPatch​(java.awt.Graphics g)
      • isOpaquePatch

        protected boolean isOpaquePatch()
      • setOpaquePatch

        protected void setOpaquePatch​(boolean opaque)
      • isAlpha

        protected boolean isAlpha()
        Returns whether or not the container hierarchy below is transparent.
        Returns:
      • isTransparentBackground

        protected boolean isTransparentBackground()
        Returns whether or not the background is transparent.
        Returns:
      • isPaintingBackground

        protected boolean isPaintingBackground()
        Returns whether or not the background should be painted.
        Returns: