Loading...
Searching...
No Matches
juce::Component Class Reference

## Detailed Description

The base class for all JUCE user-interface objects.

The documentation for this class was generated from the following file:

- juce_gui_basics/components/juce_Component.h

Inheritance diagram for juce::Component:

## Classes

class | SafePointer
| Holds a pointer to some type of Component, which automatically becomes null if the component is deleted. More...
class | BailOutChecker
| A class to keep an eye on a component and check for it being deleted. More...
class | Positioner
| Base class for objects that can be used to automatically position a component according to some kind of algorithm. More...

## Public Types

enum class | WindowControlKind { client , caption , minimise , maximise , close , sizeTop , sizeLeft , sizeRight , sizeBottom , sizeTopLeft , sizeTopRight , sizeBottomLeft , sizeBottomRight }
| Types of control that are commonly found in windows, especially title-bars. More...
enum class | FocusContainerType { none , focusContainer , keyboardFocusContainer }
| A focus container type that can be passed to setFocusContainerType(). More...
enum | FocusChangeType { focusChangedByMouseClick , focusChangedByTabKey , focusChangedDirectly }
| Enumeration used by the focusGained() and focusLost() methods. More...
enum class | FocusChangeDirection { unknown , forward , backward }
| Enumeration used by the focusGainedWithDirection() method. More...

## Public Member Functions

| Component () noexcept
| Creates a component.
| ~Component () override
| Destructor.
| Component (const String &componentName) noexcept
| Creates a component, setting its name at the same time.
String | getName () const noexcept
| Returns the name of this component.
virtual void | setName (const String &newName)
| Sets the name of this component.
String | getComponentID () const noexcept
| Returns the ID string that was set by setComponentID().
void | setComponentID (const String &newID)
| Sets the component's ID string.
virtual void | setVisible (bool shouldBeVisible)
| Makes the component visible or invisible.
bool | isVisible () const noexcept
| Tests whether the component is visible or not.
virtual void | visibilityChanged ()
| Called when this component's visibility changes.
bool | isShowing () const
| Tests whether this component and all its parents are visible.
virtual void | addToDesktop (int windowStyleFlags, void *nativeWindowToAttachTo=nullptr)
| Makes this component appear as a window on the desktop.
void | removeFromDesktop ()
| If the component is currently showing on the desktop, this will hide it.
bool | isOnDesktop () const noexcept
| Returns true if this component is currently showing on the desktop.
ComponentPeer * | getPeer () const
| Returns the heavyweight window that contains this component.
virtual void | userTriedToCloseWindow ()
| For components on the desktop, this is called if the system wants to close the window.
virtual void | minimisationStateChanged (bool isNowMinimised)
| Called for a desktop component which has just been minimised or un-minimised.
virtual float | getDesktopScaleFactor () const
| Returns the default scale factor to use for this component when it is placed on the desktop.
void | toFront (bool shouldAlsoGainKeyboardFocus)
| Brings the component to the front of its siblings.
void | toBack ()
| Changes this component's z-order to be at the back of all its siblings.
void | toBehind (Component *other)
| Changes this component's z-order so that it's just behind another component.
void | setAlwaysOnTop (bool shouldStayOnTop)
| Sets whether the component should always be kept at the front of its siblings.
bool | isAlwaysOnTop () const noexcept
| Returns true if this component is set to always stay in front of its siblings.
int | getX () const noexcept
| Returns the x coordinate of the component's left edge.
int | getY () const noexcept
| Returns the y coordinate of the top of this component.
int | getWidth () const noexcept
| Returns the component's width in pixels.
int | getHeight () const noexcept
| Returns the component's height in pixels.
int | getRight () const noexcept
| Returns the x coordinate of the component's right-hand edge.
Point< int > | getPosition () const noexcept
| Returns the component's top-left position as a Point.
int | getBottom () const noexcept
| Returns the y coordinate of the bottom edge of this component.
Rectangle< int > | getBounds () const noexcept
| Returns this component's bounding box.
Rectangle< int > | getLocalBounds () const noexcept
| Returns the component's bounds, relative to its own origin.
Rectangle< int > | getBoundsInParent () const noexcept
| Returns the area of this component's parent which this component covers.
int | getScreenX () const
| Returns this component's x coordinate relative the screen's top-left origin.
int | getScreenY () const
| Returns this component's y coordinate relative the screen's top-left origin.
Point< int > | getScreenPosition () const
| Returns the position of this component's top-left corner relative to the screen's top-left.
Rectangle< int > | getScreenBounds () const
| Returns the bounds of this component, relative to the screen's top-left.
Point< int > | getLocalPoint (const Component *sourceComponent, Point< int > pointRelativeToSourceComponent) const
| Converts a point to be relative to this component's coordinate space.
Point< float > | getLocalPoint (const Component *sourceComponent, Point< float > pointRelativeToSourceComponent) const
| Converts a point to be relative to this component's coordinate space.
Rectangle< int > | getLocalArea (const Component *sourceComponent, Rectangle< int > areaRelativeToSourceComponent) const
| Converts a rectangle to be relative to this component's coordinate space.
Rectangle< float > | getLocalArea (const Component *sourceComponent, Rectangle< float > areaRelativeToSourceComponent) const
| Converts a rectangle to be relative to this component's coordinate space.
Point< int > | localPointToGlobal (Point< int > localPoint) const
| Converts a point relative to this component's top-left into a screen coordinate.
Point< float > | localPointToGlobal (Point< float > localPoint) const
| Converts a point relative to this component's top-left into a screen coordinate.
Rectangle< int > | localAreaToGlobal (Rectangle< int > localArea) const
| Converts a rectangle from this component's coordinate space to a screen coordinate.
Rectangle< float > | localAreaToGlobal (Rectangle< float > localArea) const
| Converts a rectangle from this component's coordinate space to a screen coordinate.
void | setTopLeftPosition (int x, int y)
| Moves the component to a new position.
void | setTopLeftPosition (Point< int > newTopLeftPosition)
| Moves the component to a new position.
void | setTopRightPosition (int x, int y)
| Moves the component to a new position.
void | setTopRightPosition (Point< int >)
| Moves the component to a new position.
void | setSize (int newWidth, int newHeight)
| Changes the size of the component.
void | setBounds (int x, int y, int width, int height)
| Changes the component's position and size.
void | setBounds (Rectangle< int > newBounds)
| Changes the component's position and size.
void | setBoundsRelative (float proportionalX, float proportionalY, float proportionalWidth, float proportionalHeight)
| Changes the component's position and size in terms of fractions of its parent's size.
void | setBoundsRelative (Rectangle< float > proportionalArea)
| Changes the component's position and size in terms of fractions of its parent's size.
void | setBoundsInset (BorderSize< int > borders)
| Changes the component's position and size based on the amount of space to leave around it.
void | setBoundsToFit (Rectangle< int > targetArea, Justification justification, bool onlyReduceInSize)
| Positions the component within a given rectangle, keeping its proportions unchanged.
void | setCentrePosition (int x, int y)
| Changes the position of the component's centre.
void | setCentrePosition (Point< int > newCentrePosition)
| Changes the position of the component's centre.
void | setCentreRelative (float x, float y)
| Changes the position of the component's centre.
void | centreWithSize (int width, int height)
| Changes the component's size and centres it within its parent.
void | setTransform (const AffineTransform &transform)
| Sets a transform matrix to be applied to this component.
AffineTransform | getTransform () const
| Returns the transform that is currently being applied to this component.
bool | isTransformed () const noexcept
| Returns true if a non-identity transform is being applied to this component.
int | proportionOfWidth (float proportion) const noexcept
| Returns a proportion of the component's width.
int | proportionOfHeight (float proportion) const noexcept
| Returns a proportion of the component's height.
int | getParentWidth () const noexcept
| Returns the width of the component's parent.
int | getParentHeight () const noexcept
| Returns the height of the component's parent.
Rectangle< int > | getParentMonitorArea () const
| Returns the screen coordinates of the monitor that contains this component.
int | getNumChildComponents () const noexcept
| Returns the number of child components that this component contains.
Component * | getChildComponent (int index) const noexcept
| Returns one of this component's child components, by it index.
int | getIndexOfChildComponent (const Component *child) const noexcept
| Returns the index of this component in the list of child components.
const Array< Component * > & | getChildren () const noexcept
| Provides access to the underlying array of child components.
Component * | findChildWithID (StringRef componentID) const noexcept
| Looks for a child component with the specified ID.
void | addChildComponent (Component *child, int zOrder=-1)
| Adds a child component to this one.
void | addChildComponent (Component &child, int zOrder=-1)
| Adds a child component to this one.
void | addAndMakeVisible (Component *child, int zOrder=-1)
| Adds a child component to this one, and also makes the child visible if it isn't already.
void | addAndMakeVisible (Component &child, int zOrder=-1)
| Adds a child component to this one, and also makes the child visible if it isn't already.
void | addChildAndSetID (Component *child, const String &componentID)
| Adds a child component to this one, makes it visible, and sets its component ID.
void | removeChildComponent (Component *childToRemove)
| Removes one of this component's child-components.
Component * | removeChildComponent (int childIndexToRemove)
| Removes one of this component's child-components by index.
void | removeAllChildren ()
| Removes all this component's children.
void | deleteAllChildren ()
| Removes and deletes all of this component's children.
Component * | getParentComponent () const noexcept
| Returns the component which this component is inside.
template<class TargetClass>
TargetClass * | findParentComponentOfClass () const
| Searches the parent components for a component of a specified class.
Component * | getTopLevelComponent () const noexcept
| Returns the highest-level component which contains this one or its parents.
bool | isParentOf (const Component *possibleChild) const noexcept
| Checks whether a component is anywhere inside this component or its children.
virtual void | parentHierarchyChanged ()
| Called to indicate that the component's parents have changed.
virtual void | childrenChanged ()
| Subclasses can use this callback to be told when children are added or removed, or when their z-order changes.
virtual bool | hitTest (int x, int y)
| Tests whether a given point is inside the component.
virtual WindowControlKind | findControlAtPoint (Point< float >) const
| For components that are added to the desktop, this may be called to determine what kind of control is at particular locations in the window.
virtual void | windowControlClickedClose ()
| For components that are added to the desktop, this may be called to indicate that the mouse was clicked inside the area of the "close" control.
virtual void | windowControlClickedMinimise ()
| For components that are added to the desktop, this may be called to indicate that the mouse was clicked inside the area of the "minimise" control.
virtual void | windowControlClickedMaximise ()
| For components that are added to the desktop, this may be called to indicate that the mouse was clicked inside the area of the "maximise" control.
void | setInterceptsMouseClicks (bool allowClicksOnThisComponent, bool allowClicksOnChildComponents) noexcept
| Changes the default return value for the hitTest() method.
void | getInterceptsMouseClicks (bool &allowsClicksOnThisComponent, bool &allowsClicksOnChildComponents) const noexcept
| Retrieves the current state of the mouse-click interception flags.
bool | contains (Point< int > localPoint)
| Returns true if a given point lies within this component or one of its children.
bool | contains (Point< float > localPoint)
| Returns true if a given point lies within this component or one of its children.
bool | reallyContains (Point< int > localPoint, bool returnTrueIfWithinAChild)
| Returns true if a given point lies in this component, taking any overlapping siblings into account.
bool | reallyContains (Point< float > localPoint, bool returnTrueIfWithinAChild)
| Returns true if a given point lies in this component, taking any overlapping siblings into account.
Component * | getComponentAt (int x, int y)
| Returns the component at a certain point within this one.
Component * | getComponentAt (Point< int > position)
| Returns the component at a certain point within this one.
Component * | getComponentAt (Point< float > position)
| Returns the component at a certain point within this one.
void | repaint ()
| Marks the whole component as needing to be redrawn.
void | repaint (int x, int y, int width, int height)
| Marks a subsection of this component as needing to be redrawn.
void | repaint (Rectangle< int > area)
| Marks a subsection of this component as needing to be redrawn.
void | setBufferedToImage (bool shouldBeBuffered)
| Makes the component use an internal buffer to optimise its redrawing.
Image | createComponentSnapshot (Rectangle< int > areaToGrab, bool clipImageToComponentBounds=true, float scaleFactor=1.0f, const ImageType &imageType=NativeImageType{})
| Generates a snapshot of part of this component.
void | paintEntireComponent (Graphics &context, bool ignoreAlphaLevel)
| Draws this component and all its subcomponents onto the specified graphics context.
void | setPaintingIsUnclipped (bool shouldPaintWithoutClipping) noexcept
| This allows you to indicate that this component doesn't require its graphics context to be clipped when it is being painted.
bool | isPaintingUnclipped () const noexcept
| Returns true if this component doesn't require its graphics context to be clipped when it is being painted.
void | setComponentEffect (ImageEffectFilter *newEffect)
| Adds an effect filter to alter the component's appearance.
ImageEffectFilter * | getComponentEffect () const noexcept
| Returns the current component effect.
LookAndFeel & | getLookAndFeel () const noexcept
| Finds the appropriate look-and-feel to use for this component.
void | setLookAndFeel (LookAndFeel *newLookAndFeel)
| Sets the look and feel to use for this component.
FontOptions | withDefaultMetrics (FontOptions opt) const
| Returns a copy of the FontOptions with the default metrics kind from the component's LookAndFeel.
virtual void | lookAndFeelChanged ()
| Called to let the component react to a change in the look-and-feel setting.
void | sendLookAndFeelChange ()
| Calls the methods repaint(), lookAndFeelChanged(), and colourChanged() in this component and all its children recursively.
void | setOpaque (bool shouldBeOpaque)
| Indicates whether any parts of the component might be transparent.
bool | isOpaque () const noexcept
| Returns true if no parts of this component are transparent.
void | setBroughtToFrontOnMouseClick (bool shouldBeBroughtToFront) noexcept
| Indicates whether the component should be brought to the front when clicked.
bool | isBroughtToFrontOnMouseClick () const noexcept
| Indicates whether the component should be brought to the front when clicked-on.
void | setExplicitFocusOrder (int newFocusOrderIndex)
| Sets the focus order of this component.
int | getExplicitFocusOrder () const
| Returns the focus order of this component, if one has been specified.
void | setFocusContainerType (FocusContainerType containerType) noexcept
| Sets whether this component is a container for components that can have their focus traversed, and the type of focus traversal that it supports.
bool | isFocusContainer () const noexcept
| Returns true if this component has been marked as a focus container.
bool | isKeyboardFocusContainer () const noexcept
| Returns true if this component has been marked as a keyboard focus container.
Component * | findFocusContainer () const
| Returns the focus container for this component.
Component * | findKeyboardFocusContainer () const
| Returns the keyboard focus container for this component.
void | setWantsKeyboardFocus (bool wantsFocus) noexcept
| Sets a flag to indicate whether this component wants keyboard focus or not.
bool | getWantsKeyboardFocus () const noexcept
| Returns true if the component is interested in getting keyboard focus.
void | setMouseClickGrabsKeyboardFocus (bool shouldGrabFocus)
| Chooses whether a click on this component automatically grabs the focus.
bool | getMouseClickGrabsKeyboardFocus () const noexcept
| Returns the last value set with setMouseClickGrabsKeyboardFocus().
void | grabKeyboardFocus ()
| Tries to give keyboard focus to this component.
void | giveAwayKeyboardFocus ()
| If this component or any of its children currently have the keyboard focus, this will defocus it, send a focus change notification, and try to pass the focus to the next component.
bool | hasKeyboardFocus (bool trueIfChildIsFocused) const
| Returns true if this component currently has the keyboard focus.
void | moveKeyboardFocusToSibling (bool moveToNext)
| Tries to move the keyboard focus to one of this component's siblings.
virtual std::unique_ptr< ComponentTraverser > | createFocusTraverser ()
| Creates a ComponentTraverser object to determine the logic by which focus should be passed from this component.
virtual std::unique_ptr< ComponentTraverser > | createKeyboardFocusTraverser ()
| Creates a ComponentTraverser object to use to determine the logic by which keyboard focus should be passed from this component.
void | setHasFocusOutline (bool hasFocusOutline) noexcept
| Use this to indicate that the component should have an outline drawn around it when it has keyboard focus.
bool | hasFocusOutline () const noexcept
| Returns true if this component should have a focus outline.
bool | isEnabled () const noexcept
| Returns true if the component (and all its parents) are enabled.
void | setEnabled (bool shouldBeEnabled)
| Enables or disables this component.
virtual void | enablementChanged ()
| Callback to indicate that this component has been enabled or disabled.
float | getAlpha () const noexcept
| Returns the component's current transparency level.
void | setAlpha (float newAlpha)
| Changes the transparency of this component.
virtual void | alphaChanged ()
| Called when setAlpha() is used to change the alpha value of this component.
void | setMouseCursor (const MouseCursor &cursorType)
| Changes the mouse cursor shape to use when the mouse is over this component.
virtual MouseCursor | getMouseCursor ()
| Returns the mouse cursor shape to use when the mouse is over this component.
void | updateMouseCursor () const
| Forces the current mouse cursor to be updated.
virtual void | paint (Graphics &g)
| Components can override this method to draw their content.
virtual void | paintOverChildren (Graphics &g)
| Components can override this method to draw over the top of their children.
void | mouseMove (const MouseEvent &event) override
| Called when the mouse moves inside a component.
void | mouseEnter (const MouseEvent &event) override
| Called when the mouse first enters a component.
void | mouseExit (const MouseEvent &event) override
| Called when the mouse moves out of a component.
void | mouseDown (const MouseEvent &event) override
| Called when a mouse button is pressed.
void | mouseDrag (const MouseEvent &event) override
| Called when the mouse is moved while a button is held down.
void | mouseUp (const MouseEvent &event) override
| Called when a mouse button is released.
void | mouseDoubleClick (const MouseEvent &event) override
| Called when a mouse button has been double-clicked on a component.
void | mouseWheelMove (const MouseEvent &event, const MouseWheelDetails &wheel) override
| Called when the mouse-wheel is moved.
void | mouseMagnify (const MouseEvent &event, float scaleFactor) override
| Called when a pinch-to-zoom mouse-gesture is used.
void | setRepaintsOnMouseActivity (bool shouldRepaint) noexcept
| Causes automatic repaints when the mouse enters or exits this component.
void | addMouseListener (MouseListener *newListener, bool wantsEventsForAllNestedChildComponents)
| Registers a listener to be told when mouse events occur in this component.
void | removeMouseListener (MouseListener *listenerToRemove)
| Deregisters a mouse listener.
void | addKeyListener (KeyListener *newListener)
| Adds a listener that wants to hear about keypresses that this component receives.
void | removeKeyListener (KeyListener *listenerToRemove)
| Removes a previously-registered key listener.
virtual bool | keyPressed (const KeyPress &key)
| Called when a key is pressed.
virtual bool | keyStateChanged (bool isKeyDown)
| Called when a key is pressed or released.
virtual void | modifierKeysChanged (const ModifierKeys &modifiers)
| Called when a modifier key is pressed or released.
virtual void | focusGained (FocusChangeType cause)
| Called to indicate that this component has just acquired the keyboard focus.
virtual void | focusGainedWithDirection (FocusChangeType cause, FocusChangeDirection direction)
| Called to indicate that this component has just acquired the keyboard focus.
virtual void | focusLost (FocusChangeType cause)
| Called to indicate that this component has just lost the keyboard focus.
virtual void | focusOfChildComponentChanged (FocusChangeType cause)
| Called to indicate a change in whether or not this component is the parent of the currently-focused component.
bool | isMouseOver (bool includeChildren=false) const
| Returns true if the mouse is currently over this component.
bool | isMouseButtonDown (bool includeChildren=false) const
| Returns true if the mouse button is currently held down in this component.
bool | isMouseOverOrDragging (bool includeChildren=false) const
| True if the mouse is over this component, or if it's being dragged in this component.
Point< int > | getMouseXYRelative () const
| Returns the mouse's current position, relative to this component.
virtual void | resized ()
| Called when this component's size has been changed.
virtual void | moved ()
| Called when this component's position has been changed.
virtual void | childBoundsChanged (Component *child)
| Called when one of this component's children is moved or resized.
virtual void | parentSizeChanged ()
| Called when this component's immediate parent has been resized.
virtual void | broughtToFront ()
| Called when this component has been moved to the front of its siblings.
void | addComponentListener (ComponentListener *newListener)
| Adds a listener to be told about changes to the component hierarchy or position.
void | removeComponentListener (ComponentListener *listenerToRemove)
| Removes a component listener.
void | postCommandMessage (int commandId)
| Dispatches a numbered message to this component.
virtual void | handleCommandMessage (int commandId)
| Called to handle a command that was sent by postCommandMessage().
int | runModalLoop ()
| Runs a component modally, waiting until the loop terminates.
void | enterModalState (bool takeKeyboardFocus=true, ModalComponentManager::Callback *callback=nullptr, bool deleteWhenDismissed=false)
| Puts the component into a modal state.
void | exitModalState (int returnValue=0)
| Ends a component's modal state.
bool | isCurrentlyModal (bool onlyConsiderForemostModalComponent=true) const noexcept
| Returns true if this component is the modal one.
bool | isCurrentlyBlockedByAnotherModalComponent () const
| Checks whether there's a modal component somewhere that's stopping this one from receiving messages.
virtual bool | canModalEventBeSentToComponent (const Component *targetComponent)
| When a component is modal, this callback allows it to choose which other components can still receive events.
virtual void | inputAttemptWhenModal ()
| Called when the user tries to click on a component that is blocked by another modal component.
NamedValueSet & | getProperties () noexcept
| Returns the set of properties that belong to this component.
const NamedValueSet & | getProperties () const noexcept
| Returns the set of properties that belong to this component.
Colour | findColour (int colourID, bool inheritFromParent=false) const
| Looks for a colour that has been registered with the given colour ID number.
void | setColour (int colourID, Colour newColour)
| Registers a colour to be used for a particular purpose.
void | removeColour (int colourID)
| If a colour has been set with setColour(), this will remove it.
bool | isColourSpecified (int colourID) const
| Returns true if the specified colour ID has been explicitly set for this component using the setColour() method.
void | copyAllExplicitColoursTo (Component &target) const
| This looks for any colours that have been specified for this component, and copies them to the specified target component.
virtual void | colourChanged ()
| This method is called when a colour is changed by the setColour() method, or when the look-and-feel is changed by the setLookAndFeel() or sendLookAndFeelChange() methods.
void * | getWindowHandle () const
| Returns the underlying native window handle for this component.
Positioner * | getPositioner () const noexcept
| Returns the Positioner object that has been set for this component.
void | setPositioner (Positioner *newPositioner)
| Sets a new Positioner object for this component.
void | setCachedComponentImage (CachedComponentImage *newCachedImage)
| Gives the component a CachedComponentImage that should be used to buffer its painting.
CachedComponentImage * | getCachedComponentImage () const noexcept
| Returns the object that was set by setCachedComponentImage().
void | invalidateCachedImageResources ()
| Invalidates cached images, both in the CachedComponentImage (if any) and the image effect state.
void | setViewportIgnoreDragFlag (bool ignoreDrag) noexcept
| Sets a flag to indicate whether mouse drag events on this Component should be ignored when it is inside a Viewport with drag-to-scroll functionality enabled.
bool | getViewportIgnoreDragFlag () const noexcept
| Retrieves the current state of the Viewport drag-to-scroll functionality flag.
String | getTitle () const noexcept
| Returns the title text for this component.
void | setTitle (const String &newTitle)
| Sets the title for this component.
String | getDescription () const noexcept
| Returns the description for this component.
void | setDescription (const String &newDescription)
| Sets the description for this component.
String | getHelpText () const noexcept
| Returns the help text for this component.
void | setHelpText (const String &newHelpText)
| Sets the help text for this component.
void | setAccessible (bool shouldBeAccessible)
| Sets whether this component and its children are visible to accessibility clients.
bool | isAccessible () const noexcept
| Returns true if this component and its children are visible to accessibility clients.
AccessibilityHandler * | getAccessibilityHandler ()
| Returns the accessibility handler for this component, or nullptr if this component is not accessible.
void | invalidateAccessibilityHandler ()
| Invalidates the AccessibilityHandler that is currently being used for this component.
virtual std::unique_ptr< AccessibilityHandler > | createAccessibilityHandler ()
| Override this method to return a custom AccessibilityHandler for this component.
Public Member Functions inherited from juce::MouseListener
virtual | ~MouseListener ()=default
| Destructor.

## Static Public Member Functions

static float JUCE_CALLTYPE | getApproximateScaleFactorForComponent (const Component *targetComponent)
| Returns the approximate scale factor for a given component by traversing its parent hierarchy and applying each transform and finally scaling this by the global scale factor.
static Component *JUCE_CALLTYPE | getCurrentlyFocusedComponent () noexcept
| Returns the component that currently has the keyboard focus.
static void JUCE_CALLTYPE | unfocusAllComponents ()
| If any component has keyboard focus, this will defocus it.
static void JUCE_CALLTYPE | beginDragAutoRepeat (int millisecondsBetweenCallbacks)
| Ensures that a non-stop stream of mouse-drag events will be sent during the current mouse-drag operation.
static bool JUCE_CALLTYPE | isMouseButtonDownAnywhere () noexcept
| Returns true if a mouse button is currently down.
static int JUCE_CALLTYPE | getNumCurrentlyModalComponents () noexcept
| Returns the number of components that are currently in a modal state.
static Component *JUCE_CALLTYPE | getCurrentlyModalComponent (int index=0) noexcept
| Returns one of the components that are currently modal.

## Member Enums

## WindowControlKind

enum class juce::Component::WindowControlKind

strong

Types of control that are commonly found in windows, especially title-bars.

Enumerator
client | Parts of the component that are not transparent and also don't have any of the following control functions.
caption | The part of a title bar that may be dragged by the mouse to move the window.
minimise | The minimise/iconify button.
maximise | The maximise/zoom button.
close | The button that dismisses the component.
sizeTop | The area that may be dragged to move the top edge of the window.
sizeLeft | The area that may be dragged to move the left edge of the window.
sizeRight | The area that may be dragged to move the right edge of the window.
sizeBottom | The area that may be dragged to move the bottom edge of the window.
sizeTopLeft | The area that may be dragged to move the top-left corner of the window.
sizeTopRight | The area that may be dragged to move the top-right corner of the window.
sizeBottomLeft | The area that may be dragged to move the bottom-left corner of the window.
sizeBottomRight | The area that may be dragged to move the bottom-right corner of the window.

## FocusContainerType

enum class juce::Component::FocusContainerType

strong

A focus container type that can be passed to setFocusContainerType().

If a component is marked as a focus container or keyboard focus container then it will act as the top-level component within which focus or keyboard focus is passed around. By default components are considered "focusable" if they are visible and enabled and "keyboard focusable" if getWantsKeyboardFocus() == true.

The order of traversal within a focus container is determined by the objects returned by createFocusTraverser() and createKeyboardFocusTraverser(), respectively - see the documentation of the default FocusContainer and KeyboardFocusContainer implementations for more information.

Enumerator
none | The component will not act as a focus container. This is the default setting for non top-level components and means that it and any sub-components are navigable within their containing focus container.

focusContainer

The component will act as a top-level component within which focus is passed around.

The default traverser implementation returned by createFocusTraverser() will use this flag to find the first parent component (of the currently focused one) that wants to be a focus container.

This is currently used when determining the hierarchy of accessible UI elements presented to screen reader clients on supported platforms. See the AccessibilityHandler class for more information.

keyboardFocusContainer

The component will act as a top-level component within which keyboard focus is passed around.

The default traverser implementation returned by createKeyboardFocusTraverser() will use this flag to find the first parent component (of the currently focused one) that wants to be a keyboard focus container.

This is currently used when determining how keyboard focus is passed between components that have been marked as keyboard focusable with setWantsKeyboardFocus() when clicking on components and navigating with the tab key.

## FocusChangeType

enum juce::Component::FocusChangeType

Enumeration used by the focusGained() and focusLost() methods.

Enumerator
focusChangedByMouseClick | Means that the user clicked the mouse to change focus.
focusChangedByTabKey | Means that the user pressed the tab key to move the focus.
focusChangedDirectly | Means that the focus was changed by a call to grabKeyboardFocus().

## FocusChangeDirection

enum class juce::Component::FocusChangeDirection

strong

Enumeration used by the focusGainedWithDirection() method.

Enumerator
unknown |
forward |
backward |

## Constructors and Destructors

## Component() [1/2]

juce::Component::Component | ( |  | ) |

noexcept

Creates a component.

To get it to actually appear, you'll also need to:

- Either add it to a parent component or use the addToDesktop() method to make it a desktop window
- Set its size and position to something sensible
- Use setVisible() to make it visible

And for it to serve any useful purpose, you'll need to write a subclass of Component or use one of the other types of component from the library.

Referenced by addAndMakeVisible(), addAndMakeVisible(), addChildAndSetID(), addChildComponent(), addChildComponent(), juce::MultiDocumentPanel::addDocument(), juce::ConcertinaPanel::addPanel(), juce::TabbedComponent::addTab(), juce::Component::Positioner::applyNewBounds(), juce::Label::attachToComponent(), juce::NSViewComponent::attachViewToComponent(), juce::Component::BailOutChecker::BailOutChecker(), juce::CallOutBox::CallOutBox(), canModalEventBeSentToComponent(), juce::CaretComponent::CaretComponent(), juce::TopLevelWindow::centreAroundComponent(), juce::AudioDeviceSelectorComponent::childBoundsChanged(), juce::CallOutBox::childBoundsChanged(), childBoundsChanged(), juce::MultiDocumentPanel::closeDocument(), juce::MultiDocumentPanel::closeDocumentAsync(), Component(), juce::Label::componentMovedOrResized(), juce::Viewport::componentMovedOrResized(), juce::MultiDocumentPanel::componentNameChanged(), juce::Label::componentParentHierarchyChanged(), ComponentPeer, juce::Label::componentVisibilityChanged(), copyAllExplicitColoursTo(), juce::CallOutBox::createAccessibilityHandler(), juce::ConcertinaPanel::createAccessibilityHandler(), juce::SidePanel::createAccessibilityHandler(), juce::TextEditor::LookAndFeelMethods::createCaretComponent(), juce::PreferencesPanel::createComponentForPage(), juce::Viewport::createScrollBarComponent(), juce::ConcertinaPanel::LookAndFeelMethods::drawConcertinaPanelHeader(), juce::Button::LookAndFeelMethods::drawTickBox(), juce::TextEditor::escapePressed(), juce::ConcertinaPanel::expandPanelFully(), findChildWithID(), findFocusContainer(), findKeyboardFocusContainer(), juce::MultiDocumentPanel::getActiveDocument(), getApproximateScaleFactorForComponent(), juce::Label::getAttachedComponent(), getChildComponent(), getChildren(), juce::Component::Positioner::getComponent(), getComponentAt(), getComponentAt(), getComponentAt(), juce::ListBox::getComponentForRowNumber(), juce::SidePanel::getContent(), juce::AudioProcessorEditor::getControlParameterIndex(), juce::TabbedComponent::getCurrentContentComponent(), getCurrentlyFocusedComponent(), getCurrentlyModalComponent(), juce::Slider::getCurrentPopupDisplay(), juce::MultiDocumentPanel::getDocument(), juce::ListBox::getHeaderComponent(), getIndexOfChildComponent(), juce::TreeView::getItemComponent(), getLocalArea(), getLocalArea(), getLocalPoint(), getLocalPoint(), juce::ConcertinaPanel::getPanel(), getParentComponent(), juce::ListBox::getRowNumberOfComponent(), juce::TabbedButtonBar::LookAndFeelMethods::getTabButtonExtraComponentBounds(), juce::TabbedComponent::getTabContentComponent(), juce::TooltipWindow::getTipFor(), juce::SidePanel::getTitleBarComponent(), getTopLevelComponent(), juce::Viewport::getViewedComponent(), isParentOf(), juce::CallOutBox::launchAsynchronously(), juce::ResizableEdgeComponent::mouseUp(), juce::MultiDocumentPanel::MultiDocumentPanelWindow, juce::OnlineUnlockForm::OverlayComp, juce::CaretComponent::paint(), juce::PreferencesPanel::paint(), juce::Component::Positioner::Positioner(), removeChildComponent(), removeChildComponent(), juce::ConcertinaPanel::removePanel(), juce::ResizableBorderComponent::ResizableBorderComponent(), juce::ResizableCornerComponent::ResizableCornerComponent(), juce::ResizableEdgeComponent::ResizableEdgeComponent(), juce::MultiDocumentPanel::setActiveDocument(), juce::SidePanel::setContent(), juce::ConcertinaPanel::setCustomPanelHeader(), juce::ConcertinaPanel::setMaximumPanelSize(), juce::ConcertinaPanel::setPanelHeaderSize(), juce::ConcertinaPanel::setPanelSize(), juce::Slider::setPopupDisplayEnabled(), juce::BubbleComponent::setPosition(), juce::SidePanel::setTitleBarComponent(), juce::Viewport::setViewedComponent(), juce::Component::BailOutChecker::shouldBailOut(), juce::TableHeaderComponent::showColumnChooserMenu(), juce::SidePanel::SidePanel(), juce::ListBox::TableListBox, toBehind(), juce::TooltipWindow::TooltipWindow(), juce::MultiDocumentPanel::tryToCloseDocument(), juce::MultiDocumentPanel::tryToCloseDocumentAsync(), juce::Viewport::viewedComponentChanged(), and ~Component().

## ~Component()

juce::Component::~Component | ( |  | ) |

override

Destructor.

Note that when a component is deleted, any child components it contains are NOT automatically deleted. It's your responsibility to manage their lifespan - you may want to use helper methods like deleteAllChildren(), or less haphazard approaches like using std::unique_ptrs or normal object aggregation to manage them.

If the component being deleted is currently the child of another one, then during deletion, it will be removed from its parent, and the parent will receive a childrenChanged() callback. Any ComponentListener objects that have registered with it will also have their ComponentListener::componentBeingDeleted() methods called.

References Component().

## Component() [2/2]

juce::Component::Component | ( | const String & | componentName | ) |

explicit noexcept

Creates a component, setting its name at the same time.

See also
  getName, setName

References Component().

## Member Functions

## getName()

String juce::Component::getName | ( |  | ) | const

inline noexcept

Returns the name of this component.

See also
  setName

References getName().

Referenced by getName().

## setName()

virtual void juce::Component::setName | ( | const String & | newName | ) |

virtual

Sets the name of this component.

When the name changes, all registered ComponentListeners will receive a ComponentListener::componentNameChanged() callback.

See also
  getName

Reimplemented in juce::DocumentWindow.

## getComponentID()

String juce::Component::getComponentID | ( |  | ) | const

inline noexcept

Returns the ID string that was set by setComponentID().

See also
  setComponentID, findChildWithID

## setComponentID()

void juce::Component::setComponentID | ( | const String & | newID | ) |

Sets the component's ID string.

You can retrieve the ID using getComponentID().

See also
  getComponentID, findChildWithID

## setVisible()

virtual void juce::Component::setVisible | ( | bool | shouldBeVisible | ) |

virtual

Makes the component visible or invisible.

This method will show or hide the component. Note that components default to being non-visible when first created. Also note that visible components won't be seen unless all their parent components are also visible.

This method will call visibilityChanged() and also componentVisibilityChanged() for any component listeners that are interested in this component.

Parameters

  shouldBeVisible | whether to show or hide the component

See also
  isVisible, isShowing, visibilityChanged, ComponentListener::componentVisibilityChanged

Reimplemented in juce::ScrollBar.

Referenced by juce::LassoComponent< SelectableItemType >::dragLasso(), and juce::LassoComponent< SelectableItemType >::endLasso().

## isVisible()

bool juce::Component::isVisible | ( |  | ) | const

inline noexcept

Tests whether the component is visible or not.

this doesn't necessarily tell you whether this comp is actually on the screen because this depends on whether all the parent components are also visible - use isShowing() to find this out.

See also
  isShowing, setVisible

## visibilityChanged()

virtual void juce::Component::visibilityChanged | ( |  | ) |

virtual

Called when this component's visibility changes.

See also
  setVisible, isVisible

Reimplemented in juce::Button, juce::ListBox, juce::ProgressBar, juce::ResizableWindow, juce::TopLevelWindow, and juce::WebBrowserComponent.

## isShowing()

bool juce::Component::isShowing | ( |  | ) | const

Tests whether this component and all its parents are visible.

Returns
  true only if this component and all its parents are visible.

See also
  isVisible

## addToDesktop()

virtual void juce::Component::addToDesktop | ( | int | windowStyleFlags,
|  | void * | nativeWindowToAttachTo = nullptr )

virtual

Makes this component appear as a window on the desktop.

Note that before calling this, you should make sure that the component's opacity is set correctly using setOpaque(). If the component is non-opaque, the windowing system will try to create a special transparent window for it, which will generally take a lot more CPU to operate (and might not even be possible on some platforms).

If the component is inside a parent component at the time this method is called, it will first be removed from that parent. Likewise if a component is on the desktop and is subsequently added to another component, it'll be removed from the desktop.

Parameters

  windowStyleFlags | a combination of the flags specified in the ComponentPeer::StyleFlags enum, which define the window's characteristics.
  nativeWindowToAttachTo | this allows an OS object to be passed-in as the window in which the juce component should place itself. On Windows, this would be a HWND, a HIViewRef on the Mac. Not necessarily supported on all platforms, and best left as 0 unless you know what you're doing.

See also
  removeFromDesktop, isOnDesktop, userTriedToCloseWindow, getPeer, ComponentPeer::setMinimised, ComponentPeer::StyleFlags, ComponentPeer::getStyleFlags, ComponentPeer::setFullScreen

Reimplemented in juce::ResizableWindow, and juce::TopLevelWindow.

## removeFromDesktop()

void juce::Component::removeFromDesktop | ( |  | ) |

If the component is currently showing on the desktop, this will hide it.

You can also use setVisible() to hide a desktop window temporarily, but removeFromDesktop() will free any system resources that are being used up.

See also
  addToDesktop, isOnDesktop

## isOnDesktop()

bool juce::Component::isOnDesktop | ( |  | ) | const

noexcept

Returns true if this component is currently showing on the desktop.

See also
  addToDesktop, removeFromDesktop

## getPeer()

ComponentPeer * juce::Component::getPeer | ( |  | ) | const

Returns the heavyweight window that contains this component.

If this component is itself on the desktop, this will return the window object that it is using. Otherwise, it will return the window of its top-level parent component.

This may return nullptr if there isn't a desktop component.

See also
  addToDesktop, isOnDesktop

References ComponentPeer, and getPeer().

Referenced by getPeer().

## userTriedToCloseWindow()

virtual void juce::Component::userTriedToCloseWindow | ( |  | ) |

virtual

For components on the desktop, this is called if the system wants to close the window.

This is a signal that either the user or the system wants the window to close. The default implementation of this method will trigger an assertion to warn you that your component should do something about it, but you can override this to ignore the event if you want.

Reimplemented in juce::AlertWindow.

References userTriedToCloseWindow().

Referenced by userTriedToCloseWindow().

## minimisationStateChanged()

virtual void juce::Component::minimisationStateChanged | ( | bool | isNowMinimised | ) |

virtual

Called for a desktop component which has just been minimised or un-minimised.

This will only be called for components on the desktop.

See also
  getPeer, ComponentPeer::setMinimised, ComponentPeer::isMinimised

References minimisationStateChanged().

Referenced by minimisationStateChanged().

## getDesktopScaleFactor()

virtual float juce::Component::getDesktopScaleFactor | ( |  | ) | const

virtual

Returns the default scale factor to use for this component when it is placed on the desktop.

The default implementation of this method just returns the value from Desktop::getGlobalScaleFactor(), but it can be overridden if a particular component has different requirements. The method only used if this component is added to the desktop - it has no effect for child components.

Reimplemented in juce::AlertWindow, juce::DialogWindow, and juce::TooltipWindow.

References getDesktopScaleFactor().

Referenced by getDesktopScaleFactor().

## toFront()

void juce::Component::toFront | ( | bool | shouldAlsoGainKeyboardFocus | ) |

Brings the component to the front of its siblings.

If some of the component's siblings have had their 'always-on-top' flag set, then they will still be kept in front of this one (unless of course this one is also 'always-on-top').

Parameters

  shouldAlsoGainKeyboardFocus | if true, this will also try to assign keyboard focus to the component (see grabKeyboardFocus() for more details)

See also
  toBack, toBehind, setAlwaysOnTop

References toFront().

Referenced by toFront().

## toBack()

void juce::Component::toBack | ( |  | ) |

Changes this component's z-order to be at the back of all its siblings.

If the component is set to be 'always-on-top', it will only be moved to the back of the other other 'always-on-top' components.

See also
  toFront, toBehind, setAlwaysOnTop

References toBack().

Referenced by toBack().

## toBehind()

void juce::Component::toBehind | ( | Component * | other | ) |

Changes this component's z-order so that it's just behind another component.

See also
  toFront, toBack

References Component(), and toBehind().

Referenced by toBehind().

## setAlwaysOnTop()

void juce::Component::setAlwaysOnTop | ( | bool | shouldStayOnTop | ) |

Sets whether the component should always be kept at the front of its siblings.

See also
  isAlwaysOnTop

References setAlwaysOnTop().

Referenced by setAlwaysOnTop().

## isAlwaysOnTop()

bool juce::Component::isAlwaysOnTop | ( |  | ) | const

noexcept

Returns true if this component is set to always stay in front of its siblings.

See also
  setAlwaysOnTop

References isAlwaysOnTop().

Referenced by isAlwaysOnTop().

## getX()

int juce::Component::getX | ( |  | ) | const

inline noexcept

Returns the x coordinate of the component's left edge.

This is a distance in pixels from the left edge of the component's parent.

Note that if you've used setTransform() to apply a transform, then the component's bounds will no longer be a direct reflection of the position at which it appears within its parent, as the transform will be applied to its bounding box.

References getX().

Referenced by getX(), and juce::StandaloneFilterWindow::~StandaloneFilterWindow().

## getY()

int juce::Component::getY | ( |  | ) | const

inline noexcept

Returns the y coordinate of the top of this component.

This is a distance in pixels from the top edge of the component's parent.

Note that if you've used setTransform() to apply a transform, then the component's bounds will no longer be a direct reflection of the position at which it appears within its parent, as the transform will be applied to its bounding box.

Referenced by juce::StandaloneFilterWindow::~StandaloneFilterWindow().

## getWidth()

int juce::Component::getWidth | ( |  | ) | const

inline noexcept

Returns the component's width in pixels.

Referenced by juce::TabbedButtonBar::getThickness(), and juce::StandaloneFilterWindow::StandaloneFilterWindow().

## getHeight()

int juce::Component::getHeight | ( |  | ) | const

inline noexcept

Returns the component's height in pixels.

Referenced by juce::TabbedButtonBar::getThickness(), and juce::StandaloneFilterWindow::StandaloneFilterWindow().

## getRight()

int juce::Component::getRight | ( |  | ) | const

inline noexcept

Returns the x coordinate of the component's right-hand edge.

This is a distance in pixels from the left edge of the component's parent.

Note that if you've used setTransform() to apply a transform, then the component's bounds will no longer be a direct reflection of the position at which it appears within its parent, as the transform will be applied to its bounding box.

## getPosition()

Point< int > juce::Component::getPosition | ( |  | ) | const

inline noexcept

Returns the component's top-left position as a Point.

## getBottom()

int juce::Component::getBottom | ( |  | ) | const

inline noexcept

Returns the y coordinate of the bottom edge of this component.

This is a distance in pixels from the top edge of the component's parent.

Note that if you've used setTransform() to apply a transform, then the component's bounds will no longer be a direct reflection of the position at which it appears within its parent, as the transform will be applied to its bounding box.

## getBounds()

Rectangle< int > juce::Component::getBounds | ( |  | ) | const

inline noexcept

Returns this component's bounding box.

The rectangle returned is relative to the top-left of the component's parent.

Note that if you've used setTransform() to apply a transform, then the component's bounds will no longer be a direct reflection of the position at which it appears within its parent, as the transform will be applied to its bounding box.

Referenced by juce::LassoComponent< SelectableItemType >::dragLasso().

## getLocalBounds()

Rectangle< int > juce::Component::getLocalBounds | ( |  | ) | const

noexcept

Returns the component's bounds, relative to its own origin.

This is like getBounds(), but returns the rectangle in local coordinates, In practice, it'll return a rectangle with position (0, 0), and the same size as this component.

## getBoundsInParent()

Rectangle< int > juce::Component::getBoundsInParent | ( |  | ) | const

noexcept

Returns the area of this component's parent which this component covers.

The returned area is relative to the parent's coordinate space. If the component has an affine transform specified, then the resulting area will be the smallest rectangle that fully covers the component's transformed bounding box. If this component has no parent, the return value will simply be the same as getBounds().

References getBoundsInParent().

Referenced by getBoundsInParent().

## getScreenX()

int juce::Component::getScreenX | ( |  | ) | const

Returns this component's x coordinate relative the screen's top-left origin.

See also
  getX, localPointToGlobal

References getScreenX().

Referenced by getScreenX().

## getScreenY()

int juce::Component::getScreenY | ( |  | ) | const

Returns this component's y coordinate relative the screen's top-left origin.

See also
  getY, localPointToGlobal

References getScreenY().

Referenced by getScreenY().

## getScreenPosition()

Point< int > juce::Component::getScreenPosition | ( |  | ) | const

Returns the position of this component's top-left corner relative to the screen's top-left.

See also
  getScreenBounds

References getScreenPosition().

Referenced by getScreenPosition().

## getScreenBounds()

Rectangle< int > juce::Component::getScreenBounds | ( |  | ) | const

Returns the bounds of this component, relative to the screen's top-left.

See also
  getScreenPosition

References getScreenBounds().

Referenced by getScreenBounds().

## getLocalPoint() [1/2]

Point< int > juce::Component::getLocalPoint | ( | const Component * | sourceComponent,
|  | Point< int > | pointRelativeToSourceComponent ) const

Converts a point to be relative to this component's coordinate space.

This takes a point relative to a different component, and returns its position relative to this component. If the sourceComponent parameter is null, the source point is assumed to be a global screen coordinate.

References Component(), and getLocalPoint().

Referenced by getLocalPoint(), and getLocalPoint().

## getLocalPoint() [2/2]

Point< float > juce::Component::getLocalPoint | ( | const Component * | sourceComponent,
|  | Point< float > | pointRelativeToSourceComponent ) const

Converts a point to be relative to this component's coordinate space.

This takes a point relative to a different component, and returns its position relative to this component. If the sourceComponent parameter is null, the source point is assumed to be a global screen coordinate.

References Component(), and getLocalPoint().

## getLocalArea() [1/2]

Rectangle< int > juce::Component::getLocalArea | ( | const Component * | sourceComponent,
|  | Rectangle< int > | areaRelativeToSourceComponent ) const

Converts a rectangle to be relative to this component's coordinate space.

This takes a rectangle that is relative to a different component, and returns its position relative to this component. If the sourceComponent parameter is null, the source rectangle is assumed to be a screen coordinate.

If you've used setTransform() to apply one or more transforms to components, then the source rectangle may not actually be rectangular when converted to the target space, so in that situation this will return the smallest rectangle that fully contains the transformed area.

References Component(), and getLocalArea().

Referenced by getLocalArea(), and getLocalArea().

## getLocalArea() [2/2]

Rectangle< float > juce::Component::getLocalArea | ( | const Component * | sourceComponent,
|  | Rectangle< float > | areaRelativeToSourceComponent ) const

Converts a rectangle to be relative to this component's coordinate space.

This takes a rectangle that is relative to a different component, and returns its position relative to this component. If the sourceComponent parameter is null, the source rectangle is assumed to be a screen coordinate.

If you've used setTransform() to apply one or more transforms to components, then the source rectangle may not actually be rectangular when converted to the target space, so in that situation this will return the smallest rectangle that fully contains the transformed area.

References Component(), and getLocalArea().

## localPointToGlobal() [1/2]

Point< int > juce::Component::localPointToGlobal | ( | Point< int > | localPoint | ) | const

Converts a point relative to this component's top-left into a screen coordinate.

See also
  getLocalPoint, localAreaToGlobal

References localPointToGlobal().

Referenced by localPointToGlobal(), and localPointToGlobal().

## localPointToGlobal() [2/2]

Point< float > juce::Component::localPointToGlobal | ( | Point< float > | localPoint | ) | const

Converts a point relative to this component's top-left into a screen coordinate.

See also
  getLocalPoint, localAreaToGlobal

References localPointToGlobal().

## localAreaToGlobal() [1/2]

Rectangle< int > juce::Component::localAreaToGlobal | ( | Rectangle< int > | localArea | ) | const

Converts a rectangle from this component's coordinate space to a screen coordinate.

If you've used setTransform() to apply one or more transforms to components, then the source rectangle may not actually be rectangular when converted to the target space, so in that situation this will return the smallest rectangle that fully contains the transformed area.

See also
  getLocalPoint, localPointToGlobal

References localAreaToGlobal().

Referenced by localAreaToGlobal(), and localAreaToGlobal().

## localAreaToGlobal() [2/2]

Rectangle< float > juce::Component::localAreaToGlobal | ( | Rectangle< float > | localArea | ) | const

Converts a rectangle from this component's coordinate space to a screen coordinate.

If you've used setTransform() to apply one or more transforms to components, then the source rectangle may not actually be rectangular when converted to the target space, so in that situation this will return the smallest rectangle that fully contains the transformed area.

See also
  getLocalPoint, localPointToGlobal

References localAreaToGlobal().

## setTopLeftPosition() [1/2]

void juce::Component::setTopLeftPosition | ( | int | x,
|  | int | y )

Moves the component to a new position.

Changes the component's top-left position (without changing its size). The position is relative to the top-left of the component's parent.

If the component actually moves, this method will make a synchronous call to moved().

Note that if you've used setTransform() to apply a transform, then the component's bounds will no longer be a direct reflection of the position at which it appears within its parent, as the transform will be applied to whatever bounds you set for it.

See also
  setBounds, ComponentListener::componentMovedOrResized

References setTopLeftPosition(), x, and y.

Referenced by setTopLeftPosition(), and setTopLeftPosition().

## setTopLeftPosition() [2/2]

void juce::Component::setTopLeftPosition | ( | Point< int > | newTopLeftPosition | ) |

Moves the component to a new position.

Changes the component's top-left position (without changing its size). The position is relative to the top-left of the component's parent.

If the component actually moves, this method will make a synchronous call to moved().

Note that if you've used setTransform() to apply a transform, then the component's bounds will no longer be a direct reflection of the position at which it appears within its parent, as the transform will be applied to whatever bounds you set for it.

See also
  setBounds, ComponentListener::componentMovedOrResized

References setTopLeftPosition().

## setTopRightPosition() [1/2]

void juce::Component::setTopRightPosition | ( | int | x,
|  | int | y )

Moves the component to a new position.

Changes the position of the component's top-right corner (keeping it the same size). The position is relative to the top-left of the component's parent.

If the component actually moves, this method will make a synchronous call to moved().

Note that if you've used setTransform() to apply a transform, then the component's bounds will no longer be a direct reflection of the position at which it appears within its parent, as the transform will be applied to whatever bounds you set for it.

References setTopRightPosition(), x, and y.

Referenced by setTopRightPosition(), and setTopRightPosition().

## setTopRightPosition() [2/2]

void juce::Component::setTopRightPosition | ( | Point< int > |  | ) |

Moves the component to a new position.

Changes the position of the component's top-right corner (keeping it the same size). The position is relative to the top-left of the component's parent.

If the component actually moves, this method will make a synchronous call to moved().

Note that if you've used setTransform() to apply a transform, then the component's bounds will no longer be a direct reflection of the position at which it appears within its parent, as the transform will be applied to whatever bounds you set for it.

References setTopRightPosition().

## setSize()

void juce::Component::setSize | ( | int | newWidth,
|  | int | newHeight )

Changes the size of the component.

A synchronous call to resized() will occur if the size actually changes.

Note that if you've used setTransform() to apply a transform, then the component's bounds will no longer be a direct reflection of the position at which it appears within its parent, as the transform will be applied to whatever bounds you set for it.

References setSize().

Referenced by juce::LassoComponent< SelectableItemType >::beginLasso(), and setSize().

## setBounds() [1/2]

void juce::Component::setBounds | ( | int | x,
|  | int | y,
|  | int | width,
|  | int | height )

Changes the component's position and size.

The coordinates are relative to the top-left of the component's parent, or relative to the origin of the screen if the component is on the desktop.

If this method changes the component's top-left position, it will make a synchronous call to moved(). If it changes the size, it will also make a call to resized().

Note that if you've used setTransform() to apply a transform, then the component's bounds will no longer be a direct reflection of the position at which it appears within its parent, as the transform will be applied to whatever bounds you set for it.

See also
  setTopLeftPosition, setSize, ComponentListener::componentMovedOrResized

References setBounds(), x, and y.

Referenced by juce::LassoComponent< SelectableItemType >::dragLasso(), setBounds(), and setBounds().

## setBounds() [2/2]

void juce::Component::setBounds | ( | Rectangle< int > | newBounds | ) |

Changes the component's position and size.

The coordinates are relative to the top-left of the component's parent, or relative to the origin of the screen if the component is on the desktop.

If this method changes the component's top-left position, it will make a synchronous call to moved(). If it changes the size, it will also make a call to resized().

Note that if you've used setTransform() to apply a transform, then the component's bounds will no longer be a direct reflection of the position at which it appears within its parent, as the transform will be applied to whatever bounds you set for it.

See also
  setBounds

References setBounds().

## setBoundsRelative() [1/2]

void juce::Component::setBoundsRelative | ( | float | proportionalX,
|  | float | proportionalY,
|  | float | proportionalWidth,
|  | float | proportionalHeight )

Changes the component's position and size in terms of fractions of its parent's size.

The values are factors of the parent's size, so for example setBoundsRelative (0.2f, 0.2f, 0.5f, 0.5f) would give it half the width and height of the parent, with its top-left position 20% of the way across and down the parent.

See also
  setBounds

References setBoundsRelative().

Referenced by setBoundsRelative(), and setBoundsRelative().

## setBoundsRelative() [2/2]

void juce::Component::setBoundsRelative | ( | Rectangle< float > | proportionalArea | ) |

Changes the component's position and size in terms of fractions of its parent's size.

The values are factors of the parent's size, so for example setBoundsRelative ({ 0.2f, 0.2f, 0.5f, 0.5f }) would give it half the width and height of the parent, with its top-left position 20% of the way across and down the parent.

See also
  setBounds

References setBoundsRelative().

## setBoundsInset()

void juce::Component::setBoundsInset | ( | BorderSize< int > | borders | ) |

Changes the component's position and size based on the amount of space to leave around it.

This will position the component within its parent, leaving the specified number of pixels around each edge.

See also
  setBounds

References setBoundsInset().

Referenced by setBoundsInset().

## setBoundsToFit()

void juce::Component::setBoundsToFit | ( | Rectangle< int > | targetArea,
|  | Justification | justification,
|  | bool | onlyReduceInSize )

Positions the component within a given rectangle, keeping its proportions unchanged.

If onlyReduceInSize is false, the component will be resized to fill as much of the rectangle as possible without changing its aspect ratio (the component's current size is used to determine its aspect ratio, so a zero-size component won't work here). If onlyReduceInSize is true, it will only be resized if it's too big to fit inside the rectangle.

It will then be positioned within the rectangle according to the justification flags specified.

See also
  setBounds

References setBoundsToFit().

Referenced by setBoundsToFit().

## setCentrePosition() [1/2]

void juce::Component::setCentrePosition | ( | int | x,
|  | int | y )

Changes the position of the component's centre.

Leaves the component's size unchanged, but sets the position of its centre relative to its parent's top-left.

See also
  setBounds

References setCentrePosition(), x, and y.

Referenced by setCentrePosition(), and setCentrePosition().

## setCentrePosition() [2/2]

void juce::Component::setCentrePosition | ( | Point< int > | newCentrePosition | ) |

Changes the position of the component's centre.

Leaves the component's size unchanged, but sets the position of its centre relative to its parent's top-left.

See also
  setBounds

References setCentrePosition().

## setCentreRelative()

void juce::Component::setCentreRelative | ( | float | x,
|  | float | y )

Changes the position of the component's centre.

Leaves the size unchanged, but positions its centre relative to its parent's size. E.g. setCentreRelative (0.5f, 0.5f) would place it centrally in its parent.

References setCentreRelative(), x, and y.

Referenced by setCentreRelative().

## centreWithSize()

void juce::Component::centreWithSize | ( | int | width,
|  | int | height )

Changes the component's size and centres it within its parent.

After changing the size, the component will be moved so that it's centred within its parent. If the component is on the desktop (or has no parent component), then it'll be centred within the main monitor area.

References centreWithSize().

Referenced by centreWithSize().

## setTransform()

void juce::Component::setTransform | ( | const AffineTransform & | transform | ) |

Sets a transform matrix to be applied to this component.

If you set a transform for a component, the component's position will be warped by it, relative to the component's parent's top-left origin. This means that the values you pass into setBounds() will no longer reflect the actual area within the parent that the component covers, as the bounds will be transformed and the component will probably end up actually appearing somewhere else within its parent.

When using transforms you need to be extremely careful when converting coordinates between the coordinate spaces of different components or the screen - you should always use getLocalPoint(), getLocalArea(), etc to do this, and never just manually add a component's position to a point in order to convert it between different components (but I'm sure you would never have done that anyway...).

Currently, transforms are not supported for desktop windows, so the transform will be ignored if you put a component on the desktop.

To remove a component's transform, simply pass AffineTransform() as the parameter to this method.

References setTransform().

Referenced by setTransform().

## getTransform()

AffineTransform juce::Component::getTransform | ( |  | ) | const

Returns the transform that is currently being applied to this component.

For more details about transforms, see setTransform().

See also
  setTransform

References getTransform().

Referenced by getTransform().

## isTransformed()

bool juce::Component::isTransformed | ( |  | ) | const

noexcept

Returns true if a non-identity transform is being applied to this component.

For more details about transforms, see setTransform().

See also
  setTransform

References isTransformed().

Referenced by isTransformed().

## getApproximateScaleFactorForComponent()

float JUCE_CALLTYPE juce::Component::getApproximateScaleFactorForComponent | ( | const Component * | targetComponent | ) |

static

Returns the approximate scale factor for a given component by traversing its parent hierarchy and applying each transform and finally scaling this by the global scale factor.

References Component(), getApproximateScaleFactorForComponent(), and JUCE_CALLTYPE.

Referenced by getApproximateScaleFactorForComponent().

## proportionOfWidth()

int juce::Component::proportionOfWidth | ( | float | proportion | ) | const

noexcept

Returns a proportion of the component's width.

This is a handy equivalent of (getWidth() * proportion).

References proportionOfWidth().

Referenced by proportionOfWidth().

## proportionOfHeight()

int juce::Component::proportionOfHeight | ( | float | proportion | ) | const

noexcept

Returns a proportion of the component's height.

This is a handy equivalent of (getHeight() * proportion).

References proportionOfHeight().

Referenced by proportionOfHeight().

## getParentWidth()

int juce::Component::getParentWidth | ( |  | ) | const

noexcept

Returns the width of the component's parent.

If the component has no parent (i.e. if it's on the desktop), this will return the width of the screen.

References getParentWidth().

Referenced by getParentWidth().

## getParentHeight()

int juce::Component::getParentHeight | ( |  | ) | const

noexcept

Returns the height of the component's parent.

If the component has no parent (i.e. if it's on the desktop), this will return the height of the screen.

References getParentHeight().

Referenced by getParentHeight().

## getParentMonitorArea()

Rectangle< int > juce::Component::getParentMonitorArea | ( |  | ) | const

Returns the screen coordinates of the monitor that contains this component.

If there's only one monitor, this will return its size - if there are multiple monitors, it will return the area of the monitor that contains the component's centre.

References getParentMonitorArea().

Referenced by getParentMonitorArea().

## getNumChildComponents()

int juce::Component::getNumChildComponents | ( |  | ) | const

noexcept

Returns the number of child components that this component contains.

See also
  getChildren, getChildComponent, getIndexOfChildComponent

References getNumChildComponents().

Referenced by getNumChildComponents().

## getChildComponent()

Component * juce::Component::getChildComponent | ( | int | index | ) | const

noexcept

Returns one of this component's child components, by it index.

The component with index 0 is at the back of the z-order, the one at the front will have index (getNumChildComponents() - 1).

If the index is out-of-range, this will return a null pointer.

See also
  getChildren, getNumChildComponents, getIndexOfChildComponent

References Component(), and getChildComponent().

Referenced by getChildComponent().

## getIndexOfChildComponent()

int juce::Component::getIndexOfChildComponent | ( | const Component * | child | ) | const

noexcept

Returns the index of this component in the list of child components.

A value of 0 means it is first in the list (i.e. behind all other components). Higher values are further towards the front.

Returns -1 if the component passed-in is not a child of this component.

See also
  getChildren, getNumChildComponents, getChildComponent, addChildComponent, toFront, toBack, toBehind

References Component(), and getIndexOfChildComponent().

Referenced by getIndexOfChildComponent().

## getChildren()

const Array< Component * > & juce::Component::getChildren | ( |  | ) | const

inline noexcept

Provides access to the underlying array of child components.

The most likely reason you may want to use this is for iteration in a range-based for loop.

References Component(), and getChildren().

Referenced by getChildren().

## findChildWithID()

Component * juce::Component::findChildWithID | ( | StringRef | componentID | ) | const

noexcept

Looks for a child component with the specified ID.

See also
  setComponentID, getComponentID

References Component().

## addChildComponent() [1/2]

void juce::Component::addChildComponent | ( | Component * | child,
|  | int | zOrder = -1 )

Adds a child component to this one.

Adding a child component does not mean that the component will own or delete the child - it's your responsibility to delete the component. Note that it's safe to delete a component without first removing it from its parent - doing so will automatically remove it and send out the appropriate notifications before the deletion completes.

If the child is already a child of this component, then no action will be taken, and its z-order will be left unchanged.

Parameters

  child | the new component to add. If the component passed-in is already the child of another component, it'll first be removed from its current parent.
  zOrder | The index in the child-list at which this component should be inserted. A value of -1 will insert it in front of the others, 0 is the back.

See also
  removeChildComponent, addAndMakeVisible, addChildAndSetID, getChild, ComponentListener::componentChildrenChanged

References Component().

Referenced by juce::ResizableWindow::getDesktopWindowStyleFlags().

## addChildComponent() [2/2]

void juce::Component::addChildComponent | ( | Component & | child,
|  | int | zOrder = -1 )

Adds a child component to this one.

Adding a child component does not mean that the component will own or delete the child - it's your responsibility to delete the component. Note that it's safe to delete a component without first removing it from its parent - doing so will automatically remove it and send out the appropriate notifications before the deletion completes.

If the child is already a child of this component, then no action will be taken, and its z-order will be left unchanged.

Parameters

  child | the new component to add. If the component passed-in is already the child of another component, it'll first be removed from its current parent.
  zOrder | The index in the child-list at which this component should be inserted. A value of -1 will insert it in front of the others, 0 is the back.

See also
  removeChildComponent, addAndMakeVisible, addChildAndSetID, getChild, ComponentListener::componentChildrenChanged

References Component().

## addAndMakeVisible() [1/2]

void juce::Component::addAndMakeVisible | ( | Component * | child,
|  | int | zOrder = -1 )

Adds a child component to this one, and also makes the child visible if it isn't already.

This is the same as calling setVisible (true) on the child and then addChildComponent(). See addChildComponent() for more details.

Parameters

  child | the new component to add. If the component passed-in is already the child of another component, it'll first be removed from its current parent.
  zOrder | The index in the child-list at which this component should be inserted. A value of -1 will insert it in front of the others, 0 is the back.

References Component().

Referenced by juce::ResizableWindow::getDesktopWindowStyleFlags(), and juce::StandaloneFilterWindow::StandaloneFilterWindow().

## addAndMakeVisible() [2/2]

void juce::Component::addAndMakeVisible | ( | Component & | child,
|  | int | zOrder = -1 )

Adds a child component to this one, and also makes the child visible if it isn't already.

This is the same as calling setVisible (true) on the child and then addChildComponent(). See addChildComponent() for more details.

Parameters

  child | the new component to add. If the component passed-in is already the child of another component, it'll first be removed from its current parent.
  zOrder | The index in the child-list at which this component should be inserted. A value of -1 will insert it in front of the others, 0 is the back.

References Component().

## addChildAndSetID()

void juce::Component::addChildAndSetID | ( | Component * | child,
|  | const String & | componentID )

Adds a child component to this one, makes it visible, and sets its component ID.

See also
  addAndMakeVisible, addChildComponent

References Component().

## removeChildComponent() [1/2]

void juce::Component::removeChildComponent | ( | Component * | childToRemove | ) |

Removes one of this component's child-components.

If the child passed-in isn't actually a child of this component (either because it's invalid or is the child of a different parent), then no action is taken.

Note that removing a child will not delete it! But it's ok to delete a component without first removing it - doing so will automatically remove it and send out the appropriate notifications before the deletion completes.

See also
  addChildComponent, ComponentListener::componentChildrenChanged

References Component().

## removeChildComponent() [2/2]

Component * juce::Component::removeChildComponent | ( | int | childIndexToRemove | ) |

Removes one of this component's child-components by index.

This will return a pointer to the component that was removed, or null if the index was out-of-range.

Note that removing a child will not delete it! But it's ok to delete a component without first removing it - doing so will automatically remove it and send out the appropriate notifications before the deletion completes.

See also
  addChildComponent, ComponentListener::componentChildrenChanged

References Component().

## removeAllChildren()

void juce::Component::removeAllChildren | ( |  | ) |

Removes all this component's children.

Note that this won't delete them! To do that, use deleteAllChildren() instead.

## deleteAllChildren()

void juce::Component::deleteAllChildren | ( |  | ) |

Removes and deletes all of this component's children.

My advice is to avoid this method! It's an old function that is only kept here for backwards-compatibility with legacy code, and should be viewed with extreme suspicion by anyone attempting to write modern C++. In almost all cases, it's much smarter to manage the lifetimes of your child components via modern RAII techniques such as simply making them member variables, or using std::unique_ptr, OwnedArray, etc to manage their lifetimes appropriately.

See also
  removeAllChildren

## getParentComponent()

Component * juce::Component::getParentComponent | ( |  | ) | const

inline noexcept

Returns the component which this component is inside.

If this is the highest-level component or hasn't yet been added to a parent, this will return null.

References Component().

Referenced by juce::LassoComponent< SelectableItemType >::beginLasso().

## findParentComponentOfClass()

template<class TargetClass>

TargetClass * juce::Component::findParentComponentOfClass | ( |  | ) | const

inline

Searches the parent components for a component of a specified class.

For example findParentComponentOfClass <MyComp>() would return the first parent component that can be dynamically cast to a MyComp, or will return nullptr if none of the parents are suitable.

## getTopLevelComponent()

Component * juce::Component::getTopLevelComponent | ( |  | ) | const

noexcept

Returns the highest-level component which contains this one or its parents.

This will search upwards in the parent-hierarchy from this component, until it finds the highest one that doesn't have a parent (i.e. is on the desktop or not yet added to a parent), and will return that.

References Component().

## isParentOf()

bool juce::Component::isParentOf | ( | const Component * | possibleChild | ) | const

noexcept

Checks whether a component is anywhere inside this component or its children.

This will recursively check through this component's children to see if the given component is anywhere inside.

References Component(), and isParentOf().

Referenced by isParentOf().

## parentHierarchyChanged()

virtual void juce::Component::parentHierarchyChanged | ( |  | ) |

virtual

Called to indicate that the component's parents have changed.

When a component is added or removed from its parent, this method will be called on all of its children (recursively - so all children of its children will also be called as well).

Subclasses can override this if they need to react to this in some way.

See also
  getParentComponent, isShowing, ComponentListener::componentParentHierarchyChanged

Reimplemented in juce::Button, juce::ComboBox, juce::Drawable, juce::DrawableComposite, juce::KeyMappingEditorComponent, juce::ListBox, juce::ScrollBar, juce::SidePanel, juce::TextEditor, juce::TopLevelWindow, and juce::WebBrowserComponent.

References parentHierarchyChanged().

Referenced by parentHierarchyChanged().

## childrenChanged()

virtual void juce::Component::childrenChanged | ( |  | ) |

virtual

Subclasses can use this callback to be told when children are added or removed, or when their z-order changes.

See also
  parentHierarchyChanged, ComponentListener::componentChildrenChanged

Reimplemented in juce::DrawableComposite.

References childrenChanged().

Referenced by childrenChanged().

## hitTest()

virtual bool juce::Component::hitTest | ( | int | x,
|  | int | y )

virtual

Tests whether a given point is inside the component.

Overriding this method allows you to create components which only intercept mouse-clicks within a user-defined area.

This is called to find out whether a particular x, y coordinate is considered to be inside the component or not, and is used by methods such as contains() and getComponentAt() to work out which component the mouse is clicked on.

Components with custom shapes will probably want to override it to perform some more complex hit-testing.

The default implementation of this method returns either 'client' or 'none', depending on the value that was set by calling setInterceptsMouseClicks() ('client' is the default return value).

Note that the hit-test region is not related to the opacity with which areas of a component are painted.

Applications should never call hitTest() directly - instead use the contains() method, because this will also test for occlusion by the component's parent.

Note that for components on the desktop, this method will be ignored, because it's not always possible to implement this behaviour on all platforms.

Parameters

  x | the x coordinate to test, relative to the left hand edge of this component. This value is guaranteed to be greater than or equal to zero, and less than the component's width
  y | the y coordinate to test, relative to the top edge of this component. This value is guaranteed to be greater than or equal to zero, and less than the component's height

Returns
  true if the click is considered to be inside the component

See also
  setInterceptsMouseClicks, contains

Reimplemented in juce::CallOutBox, juce::DrawableImage, juce::DrawableShape, juce::ImageButton, juce::LassoComponent< SelectableItemType >, juce::ResizableBorderComponent, juce::ResizableCornerComponent, and juce::TabBarButton.

References hitTest(), x, and y.

Referenced by hitTest().

## findControlAtPoint()

virtual WindowControlKind juce::Component::findControlAtPoint | ( | Point< float > |  | ) | const

inline virtual

For components that are added to the desktop, this may be called to determine what kind of control is at particular locations in the window.

On Windows, this is used to provide functionality like Aero Snap (snapping the window to half of the screen after dragging the window's caption area to the edge of the screen), double-clicking a horizontal border to stretch a window vertically, and the window tiling flyout that appears when hovering the mouse over the maximise button.

It's dangerous to call Component::contains from an overriding function, because this might call into the peer to do system hit-testing - but the system hit-test could in turn call findControlAtPoint, leading to infinite recursion. It's better to use functions like Rectangle::contains or Path::contains to test for the window control areas.

This is called by the peer. Component subclasses may override this but should not call it directly.

References client.

## windowControlClickedClose()

virtual void juce::Component::windowControlClickedClose | ( |  | ) |

inline virtual

For components that are added to the desktop, this may be called to indicate that the mouse was clicked inside the area of the "close" control.

This is currently only called on Windows.

This is called by the peer. Component subclasses may override this but should not call it directly.

## windowControlClickedMinimise()

virtual void juce::Component::windowControlClickedMinimise | ( |  | ) |

inline virtual

For components that are added to the desktop, this may be called to indicate that the mouse was clicked inside the area of the "minimise" control.

This is currently only called on Windows.

This is called by the peer. Component subclasses may override this but should not call it directly.

## windowControlClickedMaximise()

virtual void juce::Component::windowControlClickedMaximise | ( |  | ) |

inline virtual

For components that are added to the desktop, this may be called to indicate that the mouse was clicked inside the area of the "maximise" control.

This is currently only called on Windows.

This is called by the peer. Component subclasses may override this but should not call it directly.

## setInterceptsMouseClicks()

void juce::Component::setInterceptsMouseClicks | ( | bool | allowClicksOnThisComponent,
|  | bool | allowClicksOnChildComponents )

noexcept

Changes the default return value for the hitTest() method.

Setting this to false is an easy way to make a component pass all its mouse events (not just clicks) through to the components behind it.

When a component is created, the default setting for this is true.

Parameters

  allowClicksOnThisComponent | if true, hitTest() will always return true; if false, it will return false (or true for child components if allowClicksOnChildComponents is true)
  allowClicksOnChildComponents | if this is true and allowClicksOnThisComponent is false, then child components can be clicked on as normal but clicks on this component pass straight through; if this is false and allowClicksOnThisComponent is false, then neither this component nor any child components can be clicked on

See also
  hitTest, getInterceptsMouseClicks

Referenced by juce::TableHeaderComponent::showColumnChooserMenu().

## getInterceptsMouseClicks()

void juce::Component::getInterceptsMouseClicks | ( | bool & | allowsClicksOnThisComponent,
|  | bool & | allowsClicksOnChildComponents ) const

noexcept

Retrieves the current state of the mouse-click interception flags.

On return, the two parameters are set to the state used in the last call to setInterceptsMouseClicks().

See also
  setInterceptsMouseClicks

## contains() [1/2]

bool juce::Component::contains | ( | Point< int > | localPoint | ) |

Returns true if a given point lies within this component or one of its children.

Never override this method! Use hitTest to create custom hit regions.

Parameters

  localPoint | the coordinate to test, relative to this component's top-left.

Returns
  true if the point is within the component's hit-test area, but only if that part of the component isn't clipped by its parent component. Note that this won't take into account any overlapping sibling components which might be in the way - for that, see reallyContains()

See also
  hitTest, reallyContains, getComponentAt

## contains() [2/2]

bool juce::Component::contains | ( | Point< float > | localPoint | ) |

Returns true if a given point lies within this component or one of its children.

Never override this method! Use hitTest to create custom hit regions.

Parameters

  localPoint | the coordinate to test, relative to this component's top-left.

Returns
  true if the point is within the component's hit-test area, but only if that part of the component isn't clipped by its parent component. Note that this won't take into account any overlapping sibling components which might be in the way - for that, see reallyContains()

See also
  hitTest, reallyContains, getComponentAt

## reallyContains() [1/2]

bool juce::Component::reallyContains | ( | Point< int > | localPoint,
|  | bool | returnTrueIfWithinAChild )

Returns true if a given point lies in this component, taking any overlapping siblings into account.

Parameters

  localPoint | the coordinate to test, relative to this component's top-left.
  returnTrueIfWithinAChild | if the point actually lies within a child of this component, this determines whether that is counted as a hit.

See also
  contains, getComponentAt

## reallyContains() [2/2]

bool juce::Component::reallyContains | ( | Point< float > | localPoint,
|  | bool | returnTrueIfWithinAChild )

Returns true if a given point lies in this component, taking any overlapping siblings into account.

Parameters

  localPoint | the coordinate to test, relative to this component's top-left.
  returnTrueIfWithinAChild | if the point actually lies within a child of this component, this determines whether that is counted as a hit.

See also
  contains, getComponentAt

## getComponentAt() [1/3]

Component * juce::Component::getComponentAt | ( | int | x,
|  | int | y )

Returns the component at a certain point within this one.

Parameters

  x | the x coordinate to test, relative to this component's left edge.
  y | the y coordinate to test, relative to this component's top edge.

Returns
  the component that is at this position - which may be 0, this component, or one of its children. Note that overlapping siblings that might actually be in the way are not taken into account by this method - to account for these, instead call getComponentAt on the top-level parent of this component.

See also
  hitTest, contains, reallyContains

References Component(), x, and y.

## getComponentAt() [2/3]

Component * juce::Component::getComponentAt | ( | Point< int > | position | ) |

Returns the component at a certain point within this one.

Parameters

  position | the coordinate to test, relative to this component's top-left.

Returns
  the component that is at this position - which may be 0, this component, or one of its children. Note that overlapping siblings that might actually be in the way are not taken into account by this method - to account for these, instead call getComponentAt on the top-level parent of this component.

See also
  hitTest, contains, reallyContains

References Component().

## getComponentAt() [3/3]

Component * juce::Component::getComponentAt | ( | Point< float > | position | ) |

Returns the component at a certain point within this one.

Parameters

  position | the coordinate to test, relative to this component's top-left.

Returns
  the component that is at this position - which may be 0, this component, or one of its children. Note that overlapping siblings that might actually be in the way are not taken into account by this method - to account for these, instead call getComponentAt on the top-level parent of this component.

See also
  hitTest, contains, reallyContains

References Component().

## repaint() [1/3]

void juce::Component::repaint | ( |  | ) |

Marks the whole component as needing to be redrawn.

Calling this will not do any repainting immediately, but will mark the component as 'dirty'. At some point in the near future the operating system will send a paint message, which will redraw all the dirty regions of all components. There's no guarantee about how soon after calling repaint() the redraw will actually happen, and other queued events may be delivered before a redraw is done.

If the setBufferedToImage() method has been used to cause this component to use a buffer, the repaint() call will invalidate the cached buffer. If setCachedComponentImage() has been used to provide a custom image cache, that cache will be invalidated appropriately.

To redraw just a subsection of the component rather than the whole thing, use the repaint (int, int, int, int) method.

See also
  paint

## repaint() [2/3]

void juce::Component::repaint | ( | int | x,
|  | int | y,
|  | int | width,
|  | int | height )

Marks a subsection of this component as needing to be redrawn.

Calling this will not do any repainting immediately, but will mark the given region of the component as 'dirty'. At some point in the near future the operating system will send a paint message, which will redraw all the dirty regions of all components. There's no guarantee about how soon after calling repaint() the redraw will actually happen, and other queued events may be delivered before a redraw is done.

The region that is passed in will be clipped to keep it within the bounds of this component.

See also
  repaint()

References x, and y.

## repaint() [3/3]

void juce::Component::repaint | ( | Rectangle< int > | area | ) |

Marks a subsection of this component as needing to be redrawn.

Calling this will not do any repainting immediately, but will mark the given region of the component as 'dirty'. At some point in the near future the operating system will send a paint message, which will redraw all the dirty regions of all components. There's no guarantee about how soon after calling repaint() the redraw will actually happen, and other queued events may be delivered before a redraw is done.

The region that is passed in will be clipped to keep it within the bounds of this component.

See also
  repaint()

## setBufferedToImage()

void juce::Component::setBufferedToImage | ( | bool | shouldBeBuffered | ) |

Makes the component use an internal buffer to optimise its redrawing.

Setting this flag to true will cause the component to allocate an internal buffer into which it paints itself and all its child components, so that when asked to redraw itself, it can use this buffer rather than actually calling the paint() method.

Parts of the buffer are invalidated when repaint() is called on this component or its children. The buffer is then repainted at the next paint() callback.

See also
  repaint, paint, createComponentSnapshot

## createComponentSnapshot()

Image juce::Component::createComponentSnapshot | ( | Rectangle< int > | areaToGrab,
|  | bool | clipImageToComponentBounds = true,
|  | float | scaleFactor = 1.0f,
|  | const ImageType & | imageType = NativeImageType{} )

Generates a snapshot of part of this component.

This will return a new Image of type imageType, the size of the rectangle specified, containing a snapshot of the specified area of the component and all its children.

The image may or may not have an alpha-channel, depending on whether the image is opaque or not.

If the clipImageToComponentBounds parameter is true and the area is greater than the size of the component, it'll be clipped. If clipImageToComponentBounds is false then parts of the component beyond its bounds can be drawn.

See also
  paintEntireComponent

## paintEntireComponent()

void juce::Component::paintEntireComponent | ( | Graphics & | context,
|  | bool | ignoreAlphaLevel )

Draws this component and all its subcomponents onto the specified graphics context.

You should very rarely have to use this method, it's simply there in case you need to draw a component with a custom graphics context for some reason, e.g. for creating a snapshot of the component.

It calls paint(), paintOverChildren() and recursively calls paintEntireComponent() on its children in order to render the entire tree.

The graphics context may be left in an undefined state after this method returns, so you may need to reset it if you're going to use it again.

If ignoreAlphaLevel is false, then the component will be drawn with the opacity level specified by getAlpha(); if ignoreAlphaLevel is true, then this will be ignored and an alpha of 1.0 will be used.

## setPaintingIsUnclipped()

void juce::Component::setPaintingIsUnclipped | ( | bool | shouldPaintWithoutClipping | ) |

noexcept

This allows you to indicate that this component doesn't require its graphics context to be clipped when it is being painted.

Most people will never need to use this setting, but in situations where you have a very large number of simple components being rendered, and where they are guaranteed never to do any drawing beyond their own boundaries, setting this to true will reduce the overhead involved in clipping the graphics context that gets passed to the component's paint() callback.

If you enable this mode, you'll need to make sure your paint method doesn't call anything like Graphics::fillAll(), and doesn't draw beyond the component's bounds, because that'll produce artifacts. This option will have no effect on components that contain any child components.

## isPaintingUnclipped()

bool juce::Component::isPaintingUnclipped | ( |  | ) | const

noexcept

Returns true if this component doesn't require its graphics context to be clipped when it is being painted.

## setComponentEffect()

void juce::Component::setComponentEffect | ( | ImageEffectFilter * | newEffect | ) |

Adds an effect filter to alter the component's appearance.

When a component has an effect filter set, then this is applied to the results of its paint() method. There are a few preset effects, such as a drop-shadow or glow, but they can be user-defined as well.

The effect that is passed in will not be deleted by the component - the caller must take care of deleting it.

To remove an effect from a component, pass a null pointer in as the parameter.

See also
  ImageEffectFilter, DropShadowEffect, GlowEffect

References setComponentEffect().

Referenced by setComponentEffect().

## getComponentEffect()

ImageEffectFilter * juce::Component::getComponentEffect | ( |  | ) | const

noexcept

Returns the current component effect.

See also
  setComponentEffect

References getComponentEffect().

Referenced by getComponentEffect().

## getLookAndFeel()

LookAndFeel & juce::Component::getLookAndFeel | ( |  | ) | const

noexcept

Finds the appropriate look-and-feel to use for this component.

If the component hasn't had a look-and-feel explicitly set, this will return the parent's look-and-feel, or just the default one if there's no parent.

See also
  setLookAndFeel, lookAndFeelChanged

References getLookAndFeel().

Referenced by getLookAndFeel(), and juce::LassoComponent< SelectableItemType >::paint().

## setLookAndFeel()

void juce::Component::setLookAndFeel | ( | LookAndFeel * | newLookAndFeel | ) |

Sets the look and feel to use for this component.

This will also change the look and feel for any child components that haven't had their look set explicitly.

The object passed in will not be deleted by the component, so it's the caller's responsibility to manage it. It may be used at any time until this component has been deleted.

Calling this method will also invoke the sendLookAndFeelChange() method.

See also
  getLookAndFeel, lookAndFeelChanged, sendLookAndFeelChange

References setLookAndFeel().

Referenced by setLookAndFeel().

## withDefaultMetrics()

FontOptions juce::Component::withDefaultMetrics | ( | FontOptions | opt | ) | const

Returns a copy of the FontOptions with the default metrics kind from the component's LookAndFeel.

References withDefaultMetrics().

Referenced by juce::Label::callChangeListeners(), juce::CodeEditorComponent::createAccessibilityHandler(), and withDefaultMetrics().

## lookAndFeelChanged()

virtual void juce::Component::lookAndFeelChanged | ( |  | ) |

virtual

Called to let the component react to a change in the look-and-feel setting.

When the look-and-feel is changed for a component, this method, repaint(), and colourChanged() are called on the original component and all its children recursively.

It can also be triggered manually by the sendLookAndFeelChange() method, in case an application uses a LookAndFeel class that might have changed internally.

See also
  sendLookAndFeelChange, getLookAndFeel

Reimplemented in juce::AlertWindow, juce::BubbleComponent, juce::BurgerMenuComponent, juce::CallOutBox, juce::CodeEditorComponent, juce::ComboBox, juce::FileBrowserComponent, juce::FilenameComponent, juce::OnlineUnlockForm, juce::ProgressBar, juce::ResizableWindow, juce::ScrollBar, juce::Slider, juce::TabbedButtonBar, juce::TabbedComponent, juce::TextEditor, juce::Toolbar, and juce::Viewport.

References lookAndFeelChanged().

Referenced by lookAndFeelChanged().

## sendLookAndFeelChange()

void juce::Component::sendLookAndFeelChange | ( |  | ) |

Calls the methods repaint(), lookAndFeelChanged(), and colourChanged() in this component and all its children recursively.

See also
  lookAndFeelChanged

References sendLookAndFeelChange().

Referenced by sendLookAndFeelChange().

## setOpaque()

void juce::Component::setOpaque | ( | bool | shouldBeOpaque | ) |

Indicates whether any parts of the component might be transparent.

Components that always paint all of their contents with solid colour and thus completely cover any components behind them should use this method to tell the repaint system that they are opaque.

This information is used to optimise drawing, because it means that objects underneath opaque windows don't need to be painted.

By default, components are considered transparent, unless this is used to make it otherwise.

See also
  isOpaque

References setOpaque().

Referenced by setOpaque().

## isOpaque()

bool juce::Component::isOpaque | ( |  | ) | const

noexcept

Returns true if no parts of this component are transparent.

Returns
  the value that was set by setOpaque, (the default being false)

See also
  setOpaque

References isOpaque().

Referenced by isOpaque().

## setBroughtToFrontOnMouseClick()

void juce::Component::setBroughtToFrontOnMouseClick | ( | bool | shouldBeBroughtToFront | ) |

noexcept

Indicates whether the component should be brought to the front when clicked.

Setting this flag to true will cause the component to be brought to the front when the mouse is clicked somewhere inside it or its child components.

Note that a top-level desktop window might still be brought to the front by the operating system when it's clicked, depending on how the OS works.

By default this is set to false.

See also
  setMouseClickGrabsKeyboardFocus

References setBroughtToFrontOnMouseClick().

Referenced by setBroughtToFrontOnMouseClick().

## isBroughtToFrontOnMouseClick()

bool juce::Component::isBroughtToFrontOnMouseClick | ( |  | ) | const

noexcept

Indicates whether the component should be brought to the front when clicked-on.

See also
  setBroughtToFrontOnMouseClick

References isBroughtToFrontOnMouseClick().

Referenced by isBroughtToFrontOnMouseClick().

## setExplicitFocusOrder()

void juce::Component::setExplicitFocusOrder | ( | int | newFocusOrderIndex | ) |

Sets the focus order of this component.

The focus order is used by the default traverser implementation returned by createFocusTraverser() as part of its algorithm for deciding the order in which components should be traversed. A value of 0 or less is taken to mean that no explicit order is wanted, and that traversal should use other factors, like the component's position.

See also
  getExplicitFocusOrder, FocusTraverser, createFocusTraverser

References setExplicitFocusOrder().

Referenced by setExplicitFocusOrder().

## getExplicitFocusOrder()

int juce::Component::getExplicitFocusOrder | ( |  | ) | const

Returns the focus order of this component, if one has been specified.

By default components don't have a focus order - in that case, this will return 0.

See also
  setExplicitFocusOrder

References getExplicitFocusOrder().

Referenced by getExplicitFocusOrder().

## setFocusContainerType()

void juce::Component::setFocusContainerType | ( | FocusContainerType | containerType | ) |

noexcept

Sets whether this component is a container for components that can have their focus traversed, and the type of focus traversal that it supports.

See also
  FocusContainerType, isFocusContainer, isKeyboardFocusContainer, FocusTraverser, createFocusTraverser, KeyboardFocusTraverser, createKeyboardFocusTraverser

Referenced by createAccessibilityHandler().

## isFocusContainer()

bool juce::Component::isFocusContainer | ( |  | ) | const

noexcept

Returns true if this component has been marked as a focus container.

See also
  setFocusContainerType

## isKeyboardFocusContainer()

bool juce::Component::isKeyboardFocusContainer | ( |  | ) | const

noexcept

Returns true if this component has been marked as a keyboard focus container.

See also
  setFocusContainerType

References isKeyboardFocusContainer().

Referenced by isKeyboardFocusContainer().

## findFocusContainer()

Component * juce::Component::findFocusContainer | ( |  | ) | const

Returns the focus container for this component.

See also
  isFocusContainer, setFocusContainerType

References Component(), and findFocusContainer().

Referenced by findFocusContainer().

## findKeyboardFocusContainer()

Component * juce::Component::findKeyboardFocusContainer | ( |  | ) | const

Returns the keyboard focus container for this component.

See also
  isFocusContainer, setFocusContainerType

References Component(), and findKeyboardFocusContainer().

Referenced by findKeyboardFocusContainer().

## setWantsKeyboardFocus()

void juce::Component::setWantsKeyboardFocus | ( | bool | wantsFocus | ) |

noexcept

Sets a flag to indicate whether this component wants keyboard focus or not.

By default components aren't actually interested in gaining the keyboard focus, but this method can be used to turn this on.

See the grabKeyboardFocus() method for details about the way a component is chosen to receive the focus.

See also
  grabKeyboardFocus, giveAwayKeyboardFocus, getWantsKeyboardFocus

References setWantsKeyboardFocus().

Referenced by setWantsKeyboardFocus().

## getWantsKeyboardFocus()

bool juce::Component::getWantsKeyboardFocus | ( |  | ) | const

noexcept

Returns true if the component is interested in getting keyboard focus.

This returns the flag set by setWantsKeyboardFocus(). The default setting is false.

See also
  setWantsKeyboardFocus

References getWantsKeyboardFocus().

Referenced by getWantsKeyboardFocus().

## setMouseClickGrabsKeyboardFocus()

void juce::Component::setMouseClickGrabsKeyboardFocus | ( | bool | shouldGrabFocus | ) |

Chooses whether a click on this component automatically grabs the focus.

By default this is set to true, but you might want a component which can be focused, but where you don't want the user to be able to affect it directly by clicking.

References setMouseClickGrabsKeyboardFocus().

Referenced by setMouseClickGrabsKeyboardFocus().

## getMouseClickGrabsKeyboardFocus()

bool juce::Component::getMouseClickGrabsKeyboardFocus | ( |  | ) | const

noexcept

Returns the last value set with setMouseClickGrabsKeyboardFocus().

See also
  setMouseClickGrabsKeyboardFocus

References getMouseClickGrabsKeyboardFocus().

Referenced by getMouseClickGrabsKeyboardFocus().

## grabKeyboardFocus()

void juce::Component::grabKeyboardFocus | ( |  | ) |

Tries to give keyboard focus to this component.

When the user clicks on a component or its grabKeyboardFocus() method is called, the following procedure is used to work out which component should get it:

- if the component that was clicked on actually wants focus (as indicated by calling getWantsKeyboardFocus), it gets it.
- if the component itself doesn't want focus, it will try to pass it on to whichever of its children is the default component, as determined by the getDefaultComponent() implementation of the ComponentTraverser returned by createKeyboardFocusTraverser().
- if none of its children want focus at all, it will pass it up to its parent instead, unless it's a top-level component without a parent, in which case it just takes the focus itself.

Important note! It's obviously not possible for a component to be focused unless it's actually visible, on-screen, and inside a window that is also visible. So there's no point trying to call this in the component's own constructor or before all of its parent hierarchy has been fully instantiated.

See also
  giveAwayKeyboardFocus, setWantsKeyboardFocus, getWantsKeyboardFocus, hasKeyboardFocus, getCurrentlyFocusedComponent, focusGained, focusLost, keyPressed, keyStateChanged

References grabKeyboardFocus().

Referenced by grabKeyboardFocus().

## giveAwayKeyboardFocus()

void juce::Component::giveAwayKeyboardFocus | ( |  | ) |

If this component or any of its children currently have the keyboard focus, this will defocus it, send a focus change notification, and try to pass the focus to the next component.

See also
  grabKeyboardFocus, setWantsKeyboardFocus, getCurrentlyFocusedComponent, focusGained, focusLost

References giveAwayKeyboardFocus().

Referenced by giveAwayKeyboardFocus().

## hasKeyboardFocus()

bool juce::Component::hasKeyboardFocus | ( | bool | trueIfChildIsFocused | ) | const

Returns true if this component currently has the keyboard focus.

Parameters

  trueIfChildIsFocused | if this is true, then the method returns true if either this component or any of its children (recursively) have the focus. If false, the method only returns true if this component has the focus.

See also
  grabKeyboardFocus, giveAwayKeyboardFocus, setWantsKeyboardFocus, getCurrentlyFocusedComponent, focusGained, focusLost

References hasKeyboardFocus().

Referenced by hasKeyboardFocus().

## moveKeyboardFocusToSibling()

void juce::Component::moveKeyboardFocusToSibling | ( | bool | moveToNext | ) |

Tries to move the keyboard focus to one of this component's siblings.

This will try to move focus to either the next or previous component, as determined by the getNextComponent() and getPreviousComponent() implementations of the ComponentTraverser returned by createKeyboardFocusTraverser().

This is the method that is used when shifting focus by pressing the tab key.

Parameters

  moveToNext | if true, the focus will move forwards; if false, it will move backwards

See also
  grabKeyboardFocus, giveAwayKeyboardFocus, setFocusContainerType, setWantsKeyboardFocus

References moveKeyboardFocusToSibling().

Referenced by moveKeyboardFocusToSibling().

## getCurrentlyFocusedComponent()

Component *JUCE_CALLTYPE juce::Component::getCurrentlyFocusedComponent | ( |  | ) |

static noexcept

Returns the component that currently has the keyboard focus.

Returns
  the focused component, or nullptr if nothing is focused.

References Component(), getCurrentlyFocusedComponent(), and JUCE_CALLTYPE.

Referenced by getCurrentlyFocusedComponent().

## unfocusAllComponents()

void JUCE_CALLTYPE juce::Component::unfocusAllComponents | ( |  | ) |

static

If any component has keyboard focus, this will defocus it.

References JUCE_CALLTYPE, and unfocusAllComponents().

Referenced by unfocusAllComponents().

## createFocusTraverser()

virtual std::unique_ptr< ComponentTraverser > juce::Component::createFocusTraverser | ( |  | ) |

virtual

Creates a ComponentTraverser object to determine the logic by which focus should be passed from this component.

The default implementation of this method will return an instance of FocusTraverser if this component is a focus container (as determined by the setFocusContainerType() method). If the component isn't a focus container, then it will recursively call createFocusTraverser() on its parents.

If you override this to return a custom traverser object, then this component and all its sub-components will use the new object to make their focusing decisions.

References createFocusTraverser().

Referenced by createFocusTraverser().

## createKeyboardFocusTraverser()

virtual std::unique_ptr< ComponentTraverser > juce::Component::createKeyboardFocusTraverser | ( |  | ) |

virtual

Creates a ComponentTraverser object to use to determine the logic by which keyboard focus should be passed from this component.

The default implementation of this method will return an instance of KeyboardFocusTraverser if this component is a keyboard focus container (as determined by the setFocusContainerType() method). If the component isn't a keyboard focus container, then it will recursively call createKeyboardFocusTraverser() on its parents.

If you override this to return a custom traverser object, then this component and all its sub-components will use the new object to make their keyboard focusing decisions.

Reimplemented in juce::FilenameComponent, and juce::Label.

References createKeyboardFocusTraverser().

Referenced by createKeyboardFocusTraverser().

## setHasFocusOutline()

void juce::Component::setHasFocusOutline | ( | bool | hasFocusOutline | ) |

inline noexcept

Use this to indicate that the component should have an outline drawn around it when it has keyboard focus.

If this is set to true, then when the component gains keyboard focus the LookAndFeel::createFocusOutlineForComponent() method will be used to draw an outline around it.

See also
  FocusOutline, hasFocusOutline

References hasFocusOutline(), and setHasFocusOutline().

Referenced by setHasFocusOutline().

## hasFocusOutline()

bool juce::Component::hasFocusOutline | ( |  | ) | const

inline noexcept

Returns true if this component should have a focus outline.

See also
  FocusOutline, setHasFocusOutline

Referenced by setHasFocusOutline().

## isEnabled()

bool juce::Component::isEnabled | ( |  | ) | const

noexcept

Returns true if the component (and all its parents) are enabled.

Components are enabled by default, and can be disabled with setEnabled(). Exactly what difference this makes to the component depends on the type. E.g. buttons and sliders will choose to draw themselves differently, etc.

Note that if one of this component's parents is disabled, this will always return false, even if this component itself is enabled.

See also
  setEnabled, enablementChanged

Referenced by juce::Button::LookAndFeelMethods::drawTickBox().

## setEnabled()

void juce::Component::setEnabled | ( | bool | shouldBeEnabled | ) |

Enables or disables this component.

Disabling a component will also cause all of its child components to become disabled.

Similarly, enabling a component which is inside a disabled parent component won't make any difference until the parent is re-enabled.

See also
  isEnabled, enablementChanged

References setEnabled().

Referenced by setEnabled().

## enablementChanged()

virtual void juce::Component::enablementChanged | ( |  | ) |

virtual

Callback to indicate that this component has been enabled or disabled.

This can be triggered by one of the component's parent components being enabled or disabled, as well as changes to the component itself.

The default implementation of this method does nothing; your class may wish to repaint itself or something when this happens.

See also
  setEnabled, isEnabled

Reimplemented in juce::Button, juce::ComboBox, juce::DrawableButton, juce::GroupComponent, juce::Label, juce::PropertyComponent, juce::Slider, juce::TextEditor, juce::ToolbarButton, and juce::TreeView.

References enablementChanged().

Referenced by enablementChanged().

## getAlpha()

float juce::Component::getAlpha | ( |  | ) | const

noexcept

Returns the component's current transparency level.

See setAlpha() for more details.

References getAlpha().

Referenced by getAlpha().

## setAlpha()

void juce::Component::setAlpha | ( | float | newAlpha | ) |

Changes the transparency of this component.

When painted, the entire component and all its children will be rendered with this as the overall opacity level, where 0 is completely invisible, and 1.0 is fully opaque (i.e. normal).

See also
  getAlpha, alphaChanged

References setAlpha().

Referenced by setAlpha().

## alphaChanged()

virtual void juce::Component::alphaChanged | ( |  | ) |

virtual

Called when setAlpha() is used to change the alpha value of this component.

If you override this, you should also invoke the base class's implementation during your overridden function, as it performs some repainting behaviour.

Reimplemented in juce::NSViewComponent.

References alphaChanged().

Referenced by alphaChanged().

## setMouseCursor()

void juce::Component::setMouseCursor | ( | const MouseCursor & | cursorType | ) |

Changes the mouse cursor shape to use when the mouse is over this component.

Note that the cursor set by this method can be overridden by the getMouseCursor method.

See also
  MouseCursor

References setMouseCursor().

Referenced by setMouseCursor().

## getMouseCursor()

virtual MouseCursor juce::Component::getMouseCursor | ( |  | ) |

virtual

Returns the mouse cursor shape to use when the mouse is over this component.

The default implementation will return the cursor that was set by setCursor() but can be overridden for more specialised purposes, e.g. returning different cursors depending on the mouse position.

See also
  MouseCursor

Reimplemented in juce::TableHeaderComponent.

References getMouseCursor().

Referenced by getMouseCursor().

## updateMouseCursor()

void juce::Component::updateMouseCursor | ( |  | ) | const

Forces the current mouse cursor to be updated.

If you're overriding the getMouseCursor() method to control which cursor is displayed, then this will only be checked each time the user moves the mouse. So if you want to force the system to check that the cursor being displayed is up-to-date (even if the mouse is just sitting there), call this method.

(If you're changing the cursor using setMouseCursor(), you don't need to bother calling this).

References updateMouseCursor().

Referenced by updateMouseCursor().

## paint()

virtual void juce::Component::paint | ( | Graphics & | g | ) |

virtual

Components can override this method to draw their content.

The paint() method gets called when a region of a component needs redrawing, either because the component's repaint() method has been called, or because something has happened on the screen that means a section of a window needs to be redrawn.

Any child components will draw themselves over whatever this method draws. If you need to paint over the top of your child components, you can also implement the paintOverChildren() method to do this.

If you want to cause a component to redraw itself, this is done asynchronously - calling the repaint() method marks a region of the component as "dirty", and the paint() method will automatically be called sometime later, by the message thread, to paint any bits that need refreshing. In JUCE (and almost all modern UI frameworks), you never redraw something synchronously.

You should never need to call this method directly - to take a snapshot of the component you could use createComponentSnapshot() or paintEntireComponent().

Parameters

  g | the graphics context that must be used to do the drawing operations.

See also
  repaint, paintOverChildren, Graphics

Reimplemented in juce::ActiveXControlComponent, juce::AlertWindow, juce::AndroidViewComponent, juce::AudioVisualiserComponent, juce::BooleanPropertyComponent, juce::BubbleComponent, juce::Button, juce::CallOutBox, juce::CaretComponent, juce::CodeEditorComponent, juce::ComboBox, juce::DrawableImage, juce::DrawableShape, juce::DrawableText, juce::FileSearchPathListComponent, juce::GenericAudioProcessorEditor, juce::GroupComponent, juce::HWNDComponent, juce::ImageComponent, juce::ImagePreviewComponent, juce::KeyboardComponentBase, juce::Label, juce::LassoComponent< SelectableItemType >, juce::ListBox, juce::MenuBarComponent, juce::MultiChoicePropertyComponent, juce::MultiDocumentPanel, juce::NSViewComponent, juce::OnlineUnlockForm, juce::PreferencesPanel, juce::ProgressBar, juce::PropertyComponent, juce::PropertyPanel, juce::ResizableBorderComponent, juce::ResizableCornerComponent, juce::ResizableEdgeComponent, juce::ResizableWindow, juce::ScrollBar, juce::SidePanel, juce::Slider, juce::SplashScreen, juce::StretchableLayoutResizerBar, juce::SystemTrayIconComponent, juce::TabbedButtonBar, juce::TabbedComponent, juce::TableHeaderComponent, juce::TextEditor, juce::Toolbar, juce::TreeView, juce::UIViewComponent, juce::WebBrowserComponent, and juce::XEmbedComponent.

References paint().

Referenced by paint().

## paintOverChildren()

virtual void juce::Component::paintOverChildren | ( | Graphics & | g | ) |

virtual

Components can override this method to draw over the top of their children.

For most drawing operations, it's better to use the normal paint() method, but if you need to overlay something on top of the children, this can be used.

See also
  paint, Graphics

Reimplemented in juce::FilenameComponent, juce::ListBox, and juce::TextEditor.

References paintOverChildren().

Referenced by paintOverChildren().

## mouseMove()

void juce::Component::mouseMove | ( | const MouseEvent & | event | ) |

override virtual

Called when the mouse moves inside a component.

If the mouse button isn't pressed and the mouse moves over a component, this will be called to let the component react to this.

A component will always get a mouseEnter callback before a mouseMove.

Parameters

  event | details about the position and status of the mouse event, including the source component in which it occurred

See also
  mouseEnter, mouseExit, mouseDrag, contains

Reimplemented from juce::MouseListener.

Reimplemented in juce::MenuBarComponent, juce::MidiKeyboardComponent, juce::ResizableBorderComponent, juce::Slider, and juce::TableHeaderComponent.

References mouseMove().

Referenced by mouseMove().

## mouseEnter()

void juce::Component::mouseEnter | ( | const MouseEvent & | event | ) |

override virtual

Called when the mouse first enters a component.

If the mouse button isn't pressed and the mouse moves into a component, this will be called to let the component react to this.

When the mouse button is pressed and held down while being moved in or out of a component, no mouseEnter or mouseExit callbacks are made - only mouseDrag messages are sent to the component that the mouse was originally clicked on, until the button is released.

Parameters

  event | details about the position and status of the mouse event, including the source component in which it occurred

See also
  mouseExit, mouseDrag, mouseMove, contains

Reimplemented from juce::MouseListener.

Reimplemented in juce::MenuBarComponent, juce::MidiKeyboardComponent, juce::ResizableBorderComponent, juce::Slider, and juce::TableHeaderComponent.

References mouseEnter().

Referenced by mouseEnter().

## mouseExit()

void juce::Component::mouseExit | ( | const MouseEvent & | event | ) |

override virtual

Called when the mouse moves out of a component.

This will be called when the mouse moves off the edge of this component.

If the mouse button was pressed, and it was then dragged off the edge of the component and released, then this callback will happen when the button is released, after the mouseUp callback.

Parameters

  event | details about the position and status of the mouse event, including the source component in which it occurred

See also
  mouseEnter, mouseDrag, mouseMove, contains

Reimplemented from juce::MouseListener.

Reimplemented in juce::MenuBarComponent, juce::MidiKeyboardComponent, juce::Slider, and juce::TableHeaderComponent.

References mouseExit().

Referenced by mouseExit().

## mouseDown()

void juce::Component::mouseDown | ( | const MouseEvent & | event | ) |

override virtual

Called when a mouse button is pressed.

The MouseEvent object passed in contains lots of methods for finding out which button was pressed, as well as which modifier keys (e.g. shift, ctrl) were held down at the time.

Once a button is held down, the mouseDrag method will be called when the mouse moves, until the button is released.

Parameters

  event | details about the position and status of the mouse event, including the source component in which it occurred

See also
  mouseUp, mouseDrag, mouseDoubleClick, contains

Reimplemented from juce::MouseListener.

Reimplemented in juce::MenuBarComponent, juce::MidiKeyboardComponent, juce::MPEKeyboardComponent, juce::ResizableBorderComponent, juce::ResizableCornerComponent, juce::ResizableEdgeComponent, juce::ResizableWindow, juce::ScrollBar, juce::Slider, juce::StretchableLayoutResizerBar, juce::TableHeaderComponent, juce::TextEditor, juce::Toolbar, and juce::Viewport.

References mouseDown().

Referenced by mouseDown().

## mouseDrag()

void juce::Component::mouseDrag | ( | const MouseEvent & | event | ) |

override virtual

Called when the mouse is moved while a button is held down.

When a mouse button is pressed inside a component, that component receives mouseDrag callbacks each time the mouse moves, even if the mouse strays outside the component's bounds.

Parameters

  event | details about the position and status of the mouse event, including the source component in which it occurred

See also
  mouseDown, mouseUp, mouseMove, contains, setDragRepeatInterval

Reimplemented from juce::MouseListener.

Reimplemented in juce::MenuBarComponent, juce::MidiKeyboardComponent, juce::MPEKeyboardComponent, juce::ResizableBorderComponent, juce::ResizableCornerComponent, juce::ResizableEdgeComponent, juce::ResizableWindow, juce::ScrollBar, juce::SidePanel, juce::Slider, juce::StretchableLayoutResizerBar, juce::TableHeaderComponent, and juce::TextEditor.

References mouseDrag().

Referenced by mouseDrag().

## mouseUp()

void juce::Component::mouseUp | ( | const MouseEvent & | event | ) |

override virtual

Called when a mouse button is released.

A mouseUp callback is sent to the component in which a button was pressed even if the mouse is actually over a different component when the button is released.

The MouseEvent object passed in contains lots of methods for finding out which buttons were down just before they were released.

Parameters

  event | details about the position and status of the mouse event, including the source component in which it occurred

See also
  mouseDown, mouseDrag, mouseDoubleClick, contains

Reimplemented from juce::MouseListener.

Reimplemented in juce::Label, juce::ListBox, juce::MenuBarComponent, juce::MidiKeyboardComponent, juce::MPEKeyboardComponent, juce::ResizableBorderComponent, juce::ResizableCornerComponent, juce::ResizableEdgeComponent, juce::ResizableWindow, juce::ScrollBar, juce::SidePanel, juce::Slider, juce::TableHeaderComponent, and juce::TextEditor.

References mouseUp().

Referenced by mouseUp().

## mouseDoubleClick()

void juce::Component::mouseDoubleClick | ( | const MouseEvent & | event | ) |

override virtual

Called when a mouse button has been double-clicked on a component.

The MouseEvent object passed in contains lots of methods for finding out which button was pressed, as well as which modifier keys (e.g. shift, ctrl) were held down at the time.

Parameters

  event | details about the position and status of the mouse event, including the source component in which it occurred

See also
  mouseDown, mouseUp

Reimplemented from juce::MouseListener.

Reimplemented in juce::Label, juce::Slider, and juce::TextEditor.

References mouseDoubleClick().

Referenced by mouseDoubleClick().

## mouseWheelMove()

void juce::Component::mouseWheelMove | ( | const MouseEvent & | event,
|  | const MouseWheelDetails & | wheel )

override virtual

Called when the mouse-wheel is moved.

This callback is sent to the component that the mouse is over when the wheel is moved.

If not overridden, a component will forward this message to its parent, so that parent components can collect mouse-wheel messages that happen to child components which aren't interested in them. (Bear in mind that if you attach a component as a mouse-listener to other components, then those wheel moves will also end up calling this method and being passed up to the parents, which may not be what you intended to happen).

Parameters

  event | details about the mouse event
  wheel | details about the mouse wheel movement

Reimplemented from juce::MouseListener.

Reimplemented in juce::KeyboardComponentBase, juce::ListBox, juce::ScrollBar, juce::Slider, juce::TextEditor, and juce::Viewport.

References mouseWheelMove().

Referenced by mouseWheelMove().

## mouseMagnify()

void juce::Component::mouseMagnify | ( | const MouseEvent & | event,
|  | float | scaleFactor )

override virtual

Called when a pinch-to-zoom mouse-gesture is used.

If not overridden, a component will forward this message to its parent, so that parent components can collect gesture messages that are unused by child components.

Parameters

  event | details about the mouse event
  scaleFactor | a multiplier to indicate by how much the size of the target should be changed. A value of 1.0 would indicate no change, values greater than 1.0 mean it should be enlarged.

Reimplemented from juce::MouseListener.

References mouseMagnify().

Referenced by mouseMagnify().

## beginDragAutoRepeat()

void JUCE_CALLTYPE juce::Component::beginDragAutoRepeat | ( | int | millisecondsBetweenCallbacks | ) |

static

Ensures that a non-stop stream of mouse-drag events will be sent during the current mouse-drag operation.

This allows you to make sure that mouseDrag() events are sent continuously, even when the mouse isn't moving. This can be useful for things like auto-scrolling components when the mouse is near an edge.

Call this method during a mouseDown() or mouseDrag() callback, specifying the minimum interval between consecutive mouse drag callbacks. The callbacks will continue until the mouse is released, and then the interval will be reset, so you need to make sure it's called every time you begin a drag event. Passing an interval of 0 or less will cancel the auto-repeat.

See also
  mouseDrag, Desktop::beginDragAutoRepeat

References beginDragAutoRepeat(), and JUCE_CALLTYPE.

Referenced by beginDragAutoRepeat().

## setRepaintsOnMouseActivity()

void juce::Component::setRepaintsOnMouseActivity | ( | bool | shouldRepaint | ) |

noexcept

Causes automatic repaints when the mouse enters or exits this component.

If turned on, then when the mouse enters/exits, or when the button is pressed/released on the component, it will trigger a repaint.

This is handy for things like buttons that need to draw themselves differently when the mouse moves over them, and it avoids having to override all the different mouse callbacks and call repaint().

See also
  mouseEnter, mouseExit, mouseDown, mouseUp

References setRepaintsOnMouseActivity().

Referenced by setRepaintsOnMouseActivity().

## addMouseListener()

void juce::Component::addMouseListener | ( | MouseListener * | newListener,
|  | bool | wantsEventsForAllNestedChildComponents )

Registers a listener to be told when mouse events occur in this component.

If you need to get informed about mouse events in a component but can't or don't want to override its methods, you can attach any number of listeners to the component, and these will get told about the events in addition to the component's own callbacks being called.

Note that a MouseListener can also be attached to more than one component.

Parameters

  newListener | the listener to register
  wantsEventsForAllNestedChildComponents | if true, the listener will receive callbacks for events that happen to any child component within this component, including deeply-nested child components. If false, it will only be told about events that this component handles.

See also
  MouseListener, removeMouseListener

References addMouseListener().

Referenced by addMouseListener().

## removeMouseListener()

void juce::Component::removeMouseListener | ( | MouseListener * | listenerToRemove | ) |

Deregisters a mouse listener.

See also
  addMouseListener, MouseListener

References removeMouseListener().

Referenced by removeMouseListener().

## addKeyListener()

void juce::Component::addKeyListener | ( | KeyListener * | newListener | ) |

Adds a listener that wants to hear about keypresses that this component receives.

The listeners that are registered with a component are called by its keyPressed() or keyStateChanged() methods (assuming these haven't been overridden to do something else).

If you add an object as a key listener, be careful to remove it when the object is deleted, or the component will be left with a dangling pointer.

See also
  keyPressed, keyStateChanged, removeKeyListener

References addKeyListener().

Referenced by addKeyListener().

## removeKeyListener()

void juce::Component::removeKeyListener | ( | KeyListener * | listenerToRemove | ) |

Removes a previously-registered key listener.

See also
  addKeyListener

References removeKeyListener().

Referenced by removeKeyListener().

## keyPressed()

virtual bool juce::Component::keyPressed | ( | const KeyPress & | key | ) |

virtual

Called when a key is pressed.

When a key is pressed, the component that has the keyboard focus will have this method called. Remember that a component will only be given the focus if its setWantsKeyboardFocus() method has been used to enable this.

If your implementation returns true, the event will be consumed and not passed on to any other listeners. If it returns false, the key will be passed to any KeyListeners that have been registered with this component. As soon as one of these returns true, the process will stop, but if they all return false, the event will be passed upwards to this component's parent, and so on.

The default implementation of this method does nothing and returns false.

See also
  keyStateChanged, getCurrentlyFocusedComponent, addKeyListener

Reimplemented in juce::AlertWindow, juce::Button, juce::CallOutBox, juce::CodeEditorComponent, juce::ComboBox, juce::DialogWindow, juce::FileBrowserComponent, juce::ListBox, juce::MenuBarComponent, juce::MidiKeyboardComponent, juce::ScrollBar, juce::Slider, juce::TextEditor, juce::TreeView, and juce::Viewport.

References keyPressed().

Referenced by keyPressed().

## keyStateChanged()

virtual bool juce::Component::keyStateChanged | ( | bool | isKeyDown | ) |

virtual

Called when a key is pressed or released.

Whenever a key on the keyboard is pressed or released (including modifier keys like shift and ctrl), this method will be called on the component that currently has the keyboard focus. Remember that a component will only be given the focus if its setWantsKeyboardFocus() method has been used to enable this.

If your implementation returns true, the event will be consumed and not passed on to any other listeners. If it returns false, then any KeyListeners that have been registered with this component will have their keyStateChanged methods called. As soon as one of these returns true, the process will stop, but if they all return false, the event will be passed upwards to this component's parent, and so on.

The default implementation of this method does nothing and returns false.

To find out which keys are up or down at any time, see the KeyPress::isKeyCurrentlyDown() method.

Parameters

  isKeyDown | true if a key has been pressed; false if it has been released

See also
  keyPressed, KeyPress, getCurrentlyFocusedComponent, addKeyListener

Reimplemented in juce::Button, juce::ComboBox, juce::ListBox, juce::MidiKeyboardComponent, and juce::TextEditor.

References keyStateChanged().

Referenced by juce::Button::keyPressed(), and keyStateChanged().

## modifierKeysChanged()

virtual void juce::Component::modifierKeysChanged | ( | const ModifierKeys & | modifiers | ) |

virtual

Called when a modifier key is pressed or released.

Whenever the shift, control, alt or command keys are pressed or released, this method will be called.

The component that is currently under the main mouse pointer will be tried first and, if there is no component currently under the pointer, the component that currently has the keyboard focus will have this method called. Remember that a component will only be given the focus if its setWantsKeyboardFocus() method has been used to enable this.

The default implementation of this method actually calls its parent's modifierKeysChanged method, so that focused components which aren't interested in this will give their parents a chance to act on the event instead.

See also
  keyStateChanged, ModifierKeys

Reimplemented in juce::Slider.

References modifierKeysChanged().

Referenced by modifierKeysChanged().

## focusGained()

virtual void juce::Component::focusGained | ( | FocusChangeType | cause | ) |

virtual

Called to indicate that this component has just acquired the keyboard focus.

See also
  focusLost, setWantsKeyboardFocus, getCurrentlyFocusedComponent, hasKeyboardFocus

Reimplemented in juce::Button, juce::CodeEditorComponent, juce::ComboBox, juce::Label, and juce::TextEditor.

## focusGainedWithDirection()

virtual void juce::Component::focusGainedWithDirection | ( | FocusChangeType | cause,
|  | FocusChangeDirection | direction )

virtual

Called to indicate that this component has just acquired the keyboard focus.

This function is called every time focusGained() is called but it has an additional change direction parameter.

See also
  focusLost, setWantsKeyboardFocus, getCurrentlyFocusedComponent, hasKeyboardFocus

Reimplemented in juce::WebBrowserComponent, and juce::XEmbedComponent.

## focusLost()

virtual void juce::Component::focusLost | ( | FocusChangeType | cause | ) |

virtual

Called to indicate that this component has just lost the keyboard focus.

See also
  focusGained, setWantsKeyboardFocus, getCurrentlyFocusedComponent, hasKeyboardFocus

Reimplemented in juce::Button, juce::CodeEditorComponent, juce::ComboBox, juce::MidiKeyboardComponent, juce::MPEKeyboardComponent, juce::TextEditor, and juce::XEmbedComponent.

## focusOfChildComponentChanged()

virtual void juce::Component::focusOfChildComponentChanged | ( | FocusChangeType | cause | ) |

virtual

Called to indicate a change in whether or not this component is the parent of the currently-focused component.

Essentially this is called when the return value of a call to hasKeyboardFocus (true) has changed. It happens when focus moves from one of this component's children (at any depth) to a component that isn't contained in this one, (or vice-versa). Note that this method does NOT get called to when focus simply moves from one of its child components to another.

See also
  focusGained, setWantsKeyboardFocus, getCurrentlyFocusedComponent, hasKeyboardFocus

Reimplemented in juce::Slider, and juce::TopLevelWindow.

## isMouseOver()

bool juce::Component::isMouseOver | ( | bool | includeChildren = false | ) | const

Returns true if the mouse is currently over this component.

If the mouse isn't over the component, this will return false, even if the mouse is currently being dragged - so you can use this in your mouseDrag method to find out whether it's really over the component or not.

Note that when the mouse button is being held down, then the only component for which this method will return true is the one that was originally clicked on.

Also note that on a touch-screen device, this will only return true when a finger is actually down - as soon as all touch is released, isMouseOver will always return false.

If includeChildren is true, then this will also return true if the mouse is over any of the component's children (recursively) as well as the component itself.

See also
  isMouseButtonDown. isMouseOverOrDragging, mouseDrag

Referenced by juce::TabbedButtonBar::LookAndFeelMethods::createTabButtonShape(), juce::ConcertinaPanel::LookAndFeelMethods::drawConcertinaPanelHeader(), juce::ResizableWindow::LookAndFeelMethods::drawCornerResizer(), juce::ScrollBar::LookAndFeelMethods::drawScrollbar(), juce::StretchableLayoutResizerBar::LookAndFeelMethods::drawStretchableLayoutResizerBar(), juce::TabbedButtonBar::LookAndFeelMethods::drawTabButton(), juce::TabbedButtonBar::LookAndFeelMethods::drawTabButtonText(), juce::TableHeaderComponent::LookAndFeelMethods::drawTableHeaderColumn(), juce::TreeView::LookAndFeelMethods::drawTreeviewPlusMinusBox(), juce::KeyboardComponentBase::drawUpDownButton(), juce::TabbedButtonBar::LookAndFeelMethods::fillTabButtonShape(), juce::ToolbarItemComponent::paintButton(), juce::ToolbarButton::paintButtonArea(), juce::ToolbarItemComponent::paintButtonArea(), and juce::Toolbar::LookAndFeelMethods::paintToolbarButtonBackground().

## isMouseButtonDown()

bool juce::Component::isMouseButtonDown | ( | bool | includeChildren = false | ) | const

Returns true if the mouse button is currently held down in this component.

Note that this is a test to see whether the mouse is being pressed in this component, so it'll return false if called on component A when the mouse is actually being dragged in component B.

See also
  isMouseButtonDownAnywhere, isMouseOver, isMouseOverOrDragging

## isMouseOverOrDragging()

bool juce::Component::isMouseOverOrDragging | ( | bool | includeChildren = false | ) | const

True if the mouse is over this component, or if it's being dragged in this component.

This is a handy equivalent to (isMouseOver() || isMouseButtonDown()).

See also
  isMouseOver, isMouseButtonDown, isMouseButtonDownAnywhere

## isMouseButtonDownAnywhere()

bool JUCE_CALLTYPE juce::Component::isMouseButtonDownAnywhere | ( |  | ) |

static noexcept

Returns true if a mouse button is currently down.

Unlike isMouseButtonDown, this will test the current state of the buttons without regard to which component (if any) it has been pressed in.

See also
  isMouseButtonDown, ModifierKeys

References JUCE_CALLTYPE.

Referenced by juce::LassoComponent< SelectableItemType >::paint().

## getMouseXYRelative()

Point< int > juce::Component::getMouseXYRelative | ( |  | ) | const

Returns the mouse's current position, relative to this component.

The return value is relative to the component's top-left corner.

References getMouseXYRelative().

Referenced by getMouseXYRelative().

## resized()

virtual void juce::Component::resized | ( |  | ) |

virtual

Called when this component's size has been changed.

A component can implement this method to do things such as laying out its child components when its width or height changes.

The method is called synchronously as a result of the setBounds or setSize methods, so repeatedly changing a components size will repeatedly call its resized method (unlike things like repainting, where multiple calls to repaint are coalesced together).

If the component is a top-level window on the desktop, its size could also be changed by operating-system factors beyond the application's control.

See also
  moved, setSize

Reimplemented in juce::AudioDeviceSelectorComponent, juce::CallOutBox, juce::CodeEditorComponent, juce::ComboBox, juce::DialogWindow, juce::DrawableButton, juce::FileBrowserComponent, juce::FilenameComponent, juce::FileSearchPathListComponent, juce::GenericAudioProcessorEditor, juce::KeyboardComponentBase, juce::KeyMappingEditorComponent, juce::Label, juce::ListBox, juce::MenuBarComponent, juce::MultiChoicePropertyComponent, juce::MultiDocumentPanel, juce::OnlineUnlockForm, juce::PluginListComponent, juce::PreferencesPanel, juce::PropertyComponent, juce::PropertyPanel, juce::ResizableWindow, juce::ScrollBar, juce::SidePanel, juce::Slider, juce::StandaloneFilterWindow, juce::TabBarButton, juce::TabbedButtonBar, juce::TabbedComponent, juce::TableHeaderComponent, juce::TableListBox, juce::TextEditor, juce::Toolbar, juce::ToolbarButton, juce::ToolbarItemComponent, juce::ToolbarItemPalette, juce::TreeView, juce::Viewport, and juce::WebBrowserComponent.

References resized().

Referenced by resized(), and juce::StandaloneFilterWindow::resized().

## moved()

virtual void juce::Component::moved | ( |  | ) |

virtual

Called when this component's position has been changed.

This is called when the position relative to its parent changes, not when its absolute position on the screen changes (so it won't be called for all child components when a parent component is moved).

The method is called synchronously as a result of the setBounds, setTopLeftPosition or any of the other repositioning methods, and like resized(), it will be called each time those methods are called.

If the component is a top-level window on the desktop, its position could also be changed by operating-system factors beyond the application's control.

See also
  resized, setBounds

Reimplemented in juce::CallOutBox, juce::ResizableWindow, and juce::SidePanel.

References moved().

Referenced by moved().

## childBoundsChanged()

virtual void juce::Component::childBoundsChanged | ( | Component * | child | ) |

virtual

Called when one of this component's children is moved or resized.

If the parent wants to know about changes to its immediate children (not to children of its children), this is the method to override.

See also
  moved, resized, parentSizeChanged

Reimplemented in juce::AudioDeviceSelectorComponent, juce::CallOutBox, juce::DrawableComposite, juce::ResizableWindow, and juce::TabBarButton.

References childBoundsChanged(), and Component().

Referenced by childBoundsChanged().

## parentSizeChanged()

virtual void juce::Component::parentSizeChanged | ( |  | ) |

virtual

Called when this component's immediate parent has been resized.

If the component is a top-level window, this indicates that the screen size has changed.

See also
  childBoundsChanged, moved, resized

Reimplemented in juce::ResizableWindow.

References parentSizeChanged().

Referenced by parentSizeChanged().

## broughtToFront()

virtual void juce::Component::broughtToFront | ( |  | ) |

virtual

Called when this component has been moved to the front of its siblings.

The component may have been brought to the front by the toFront() method, or by the operating system if it's a top-level window.

See also
  toFront

Reimplemented in juce::MultiDocumentPanelWindow, and juce::XEmbedComponent.

References broughtToFront().

Referenced by broughtToFront().

## addComponentListener()

void juce::Component::addComponentListener | ( | ComponentListener * | newListener | ) |

Adds a listener to be told about changes to the component hierarchy or position.

Component listeners get called when this component's size, position or children change - see the ComponentListener class for more details.

Parameters

  newListener | the listener to register - if this is already registered, it will be ignored.

See also
  ComponentListener, removeComponentListener

References addComponentListener().

Referenced by addComponentListener().

## removeComponentListener()

void juce::Component::removeComponentListener | ( | ComponentListener * | listenerToRemove | ) |

Removes a component listener.

See also
  addComponentListener

References removeComponentListener().

Referenced by removeComponentListener().

## postCommandMessage()

void juce::Component::postCommandMessage | ( | int | commandId | ) |

Dispatches a numbered message to this component.

This is a quick and cheap way of allowing simple asynchronous messages to be sent to components. It's also safe, because if the component that you send the message to is a null or dangling pointer, this won't cause an error.

The command ID is later delivered to the component's handleCommandMessage() method by the application's message queue.

See also
  handleCommandMessage

References postCommandMessage().

Referenced by postCommandMessage().

## handleCommandMessage()

virtual void juce::Component::handleCommandMessage | ( | int | commandId | ) |

virtual

Called to handle a command that was sent by postCommandMessage().

This is called by the message thread when a command message arrives, and the component can override this method to process it in any way it needs to.

See also
  postCommandMessage

Reimplemented in juce::Button, juce::CallOutBox, and juce::MenuBarComponent.

References handleCommandMessage().

Referenced by handleCommandMessage().

## runModalLoop()

int juce::Component::runModalLoop | ( |  | ) |

Runs a component modally, waiting until the loop terminates.

This method first makes the component visible, brings it to the front and gives it the keyboard focus.

It then runs a loop, dispatching messages from the system message queue, but blocking all mouse or keyboard messages from reaching any components other than this one and its children.

This loop continues until the component's exitModalState() method is called (or the component is deleted), and then this method returns, returning the value passed into exitModalState().

Note that you SHOULD NEVER USE THIS METHOD! Modal loops are a dangerous construct because things that happen during the events that they dispatch could affect the state of objects which are currently in use somewhere on the stack, so when the loop finishes and the stack unwinds, horrible problems can occur. This is especially bad in plugins, where the host may choose to delete the plugin during runModalLoop(), so that when it returns, the entire DLL could have been unloaded from memory! Also, some OSes deliberately make it impossible to run modal loops (e.g. Android), so this method won't even exist on some platforms.

See also
  enterModalState, exitModalState, isCurrentlyModal, getCurrentlyModalComponent, isCurrentlyBlockedByAnotherModalComponent, ModalComponentManager

## enterModalState()

void juce::Component::enterModalState | ( | bool | takeKeyboardFocus = true,
|  | ModalComponentManager::Callback * | callback = nullptr,
|  | bool | deleteWhenDismissed = false )

Puts the component into a modal state.

This makes the component modal, so that messages are blocked from reaching any components other than this one and its children, but unlike runModalLoop(), this method returns immediately.

If takeKeyboardFocus is true, the component will use grabKeyboardFocus() to get the focus, which is usually what you'll want it to do. If not, it will leave the focus unchanged.

The callback is an optional object which will receive a callback when the modal component loses its modal status, either by being hidden or when exitModalState() is called. If you pass an object in here, the system will take care of deleting it later, after making the callback.

If deleteWhenDismissed is true, then when it is dismissed, the component will be deleted and then the callback will be called. (This will safely handle the situation where the component is deleted before its exitModalState() method is called).

See also
  exitModalState, runModalLoop, ModalComponentManager::attachCallback, ModalCallbackFunction

## exitModalState()

void juce::Component::exitModalState | ( | int | returnValue = 0 | ) |

Ends a component's modal state.

If this component is currently modal, this will turn off its modalness, and return a value to the runModalLoop() method that might have be running its modal loop.

See also
  runModalLoop, enterModalState, isCurrentlyModal

## isCurrentlyModal()

bool juce::Component::isCurrentlyModal | ( | bool | onlyConsiderForemostModalComponent = true | ) | const

noexcept

Returns true if this component is the modal one.

It's possible to have nested modal components, e.g. a pop-up dialog box that launches another pop-up. If onlyConsiderForemostModalComponent is true then isCurrentlyModal will only return true for the one at the top of the stack. If onlyConsiderForemostModalComponent is false then isCurrentlyModal will return true for any modal component in the stack.

See also
  getCurrentlyModalComponent

## getNumCurrentlyModalComponents()

int JUCE_CALLTYPE juce::Component::getNumCurrentlyModalComponents | ( |  | ) |

static noexcept

Returns the number of components that are currently in a modal state.

See also
  getCurrentlyModalComponent

References getNumCurrentlyModalComponents(), and JUCE_CALLTYPE.

Referenced by getNumCurrentlyModalComponents().

## getCurrentlyModalComponent()

Component *JUCE_CALLTYPE juce::Component::getCurrentlyModalComponent | ( | int | index = 0 | ) |

static noexcept

Returns one of the components that are currently modal.

The index specifies which of the possible modal components to return. The order of the components in this list is the reverse of the order in which they became modal - so the component at index 0 is always the active component, and the others are progressively earlier ones that are themselves now blocked by later ones.

Returns
  the modal component, or null if no components are modal (or if the index is out of range)

See also
  getNumCurrentlyModalComponents, runModalLoop, isCurrentlyModal

References Component(), getCurrentlyModalComponent(), and JUCE_CALLTYPE.

Referenced by getCurrentlyModalComponent().

## isCurrentlyBlockedByAnotherModalComponent()

bool juce::Component::isCurrentlyBlockedByAnotherModalComponent | ( |  | ) | const

Checks whether there's a modal component somewhere that's stopping this one from receiving messages.

If there is a modal component, its canModalEventBeSentToComponent() method will be called to see if it will still allow this component to receive events.

See also
  runModalLoop, getCurrentlyModalComponent

References isCurrentlyBlockedByAnotherModalComponent().

Referenced by isCurrentlyBlockedByAnotherModalComponent().

## canModalEventBeSentToComponent()

virtual bool juce::Component::canModalEventBeSentToComponent | ( | const Component * | targetComponent | ) |

virtual

When a component is modal, this callback allows it to choose which other components can still receive events.

When a modal component is active and the user clicks on a non-modal component, this method is called on the modal component, and if it returns true, the event is allowed to reach its target. If it returns false, the event is blocked and the inputAttemptWhenModal() callback is made.

It called by the isCurrentlyBlockedByAnotherModalComponent() method. The default implementation just returns false in all cases.

References canModalEventBeSentToComponent(), and Component().

Referenced by canModalEventBeSentToComponent().

## inputAttemptWhenModal()

virtual void juce::Component::inputAttemptWhenModal | ( |  | ) |

virtual

Called when the user tries to click on a component that is blocked by another modal component.

When a component is modal and the user clicks on one of the other components, the modal component will receive this callback.

The default implementation of this method will play a beep, and bring the currently modal component to the front, but it can be overridden to do other tasks.

See also
  isCurrentlyBlockedByAnotherModalComponent, canModalEventBeSentToComponent

Reimplemented in juce::CallOutBox, and juce::Label.

References inputAttemptWhenModal().

Referenced by inputAttemptWhenModal().

## getProperties() [1/2]

NamedValueSet & juce::Component::getProperties | ( |  | ) |

inline noexcept

Returns the set of properties that belong to this component.

Each component has a NamedValueSet object which you can use to attach arbitrary items of data to it.

References getProperties().

Referenced by getProperties().

## getProperties() [2/2]

const NamedValueSet & juce::Component::getProperties | ( |  | ) | const

inline noexcept

Returns the set of properties that belong to this component.

Each component has a NamedValueSet object which you can use to attach arbitrary items of data to it.

## findColour()

Colour juce::Component::findColour | ( | int | colourID,
|  | bool | inheritFromParent = false ) const

Looks for a colour that has been registered with the given colour ID number.

If a colour has been set for this ID number using setColour(), then it is returned. If none has been set, the method will try calling the component's LookAndFeel class's findColour() method. If none has been registered with the look-and-feel either, it will just return black.

The colour IDs for various purposes are stored as enums in the components that they are relevant to - for an example, see Slider::ColourIds, Label::ColourIds, TextEditor::ColourIds, TreeView::ColourIds, etc.

See also
  setColour, isColourSpecified, colourChanged, LookAndFeel::findColour, LookAndFeel::setColour

## setColour()

void juce::Component::setColour | ( | int | colourID,
|  | Colour | newColour )

Registers a colour to be used for a particular purpose.

Changing a colour will cause a synchronous callback to the colourChanged() method, which your component can override if it needs to do something when colours are altered.

Note repaint() is not automatically called when a colour is changed.

For more details about colour IDs, see the comments for findColour().

See also
  findColour, isColourSpecified, colourChanged, LookAndFeel::findColour, LookAndFeel::setColour

## removeColour()

void juce::Component::removeColour | ( | int | colourID | ) |

If a colour has been set with setColour(), this will remove it.

This allows you to make a colour revert to its default state.

## isColourSpecified()

bool juce::Component::isColourSpecified | ( | int | colourID | ) | const

Returns true if the specified colour ID has been explicitly set for this component using the setColour() method.

## copyAllExplicitColoursTo()

void juce::Component::copyAllExplicitColoursTo | ( | Component & | target | ) | const

This looks for any colours that have been specified for this component, and copies them to the specified target component.

References Component().

## colourChanged()

virtual void juce::Component::colourChanged | ( |  | ) |

virtual

This method is called when a colour is changed by the setColour() method, or when the look-and-feel is changed by the setLookAndFeel() or sendLookAndFeelChange() methods.

See also
  setColour, findColour, setLookAndFeel, sendLookAndFeelChange

Reimplemented in juce::ComboBox, juce::DrawableButton, juce::GroupComponent, juce::HyperlinkButton, juce::Label, juce::ListBox, juce::MidiKeyboardComponent, juce::MPEKeyboardComponent, juce::ProgressBar, juce::Slider, juce::TextButton, juce::TextPropertyComponent, juce::ToggleButton, and juce::TreeView.

## getWindowHandle()

void * juce::Component::getWindowHandle | ( |  | ) | const

Returns the underlying native window handle for this component.

This is platform-dependent and strictly for power-users only!

## getPositioner()

Positioner * juce::Component::getPositioner | ( |  | ) | const

noexcept

Returns the Positioner object that has been set for this component.

See also
  setPositioner()

## setPositioner()

void juce::Component::setPositioner | ( | Positioner * | newPositioner | ) |

Sets a new Positioner object for this component.

If there's currently another positioner set, it will be deleted. The object that is passed in will be deleted automatically by this component when it's no longer required. Pass a null pointer to clear the current positioner.

See also
  getPositioner()

References setPositioner().

Referenced by setPositioner().

## setCachedComponentImage()

void juce::Component::setCachedComponentImage | ( | CachedComponentImage * | newCachedImage | ) |

Gives the component a CachedComponentImage that should be used to buffer its painting.

The object that is passed-in will be owned by this component, and will be deleted automatically later on.

See also
  setBufferedToImage

References setCachedComponentImage().

Referenced by setCachedComponentImage().

## getCachedComponentImage()

CachedComponentImage * juce::Component::getCachedComponentImage | ( |  | ) | const

inline noexcept

Returns the object that was set by setCachedComponentImage().

See also
  setCachedComponentImage

References getCachedComponentImage().

Referenced by getCachedComponentImage().

## invalidateCachedImageResources()

void juce::Component::invalidateCachedImageResources | ( |  | ) |

Invalidates cached images, both in the CachedComponentImage (if any) and the image effect state.

## setViewportIgnoreDragFlag()

void juce::Component::setViewportIgnoreDragFlag | ( | bool | ignoreDrag | ) |

inline noexcept

Sets a flag to indicate whether mouse drag events on this Component should be ignored when it is inside a Viewport with drag-to-scroll functionality enabled.

This is useful for Components such as sliders that should not move when their parent Viewport when dragged.

## getViewportIgnoreDragFlag()

bool juce::Component::getViewportIgnoreDragFlag | ( |  | ) | const

inline noexcept

Retrieves the current state of the Viewport drag-to-scroll functionality flag.

See also
  setViewportIgnoreDragFlag

## getTitle()

String juce::Component::getTitle | ( |  | ) | const

inline noexcept

Returns the title text for this component.

See also
  setTitle

## setTitle()

void juce::Component::setTitle | ( | const String & | newTitle | ) |

Sets the title for this component.

If this component supports accessibility using the default AccessibilityHandler implementation, this string will be passed to accessibility clients requesting a title and may be read out by a screen reader.

See also
  getTitle, getAccessibilityHandler

## getDescription()

String juce::Component::getDescription | ( |  | ) | const

inline noexcept

Returns the description for this component.

See also
  setDescription

## setDescription()

void juce::Component::setDescription | ( | const String & | newDescription | ) |

Sets the description for this component.

If this component supports accessibility using the default AccessibilityHandler implementation, this string will be passed to accessibility clients requesting a description and may be read out by a screen reader.

See also
  getDescription, getAccessibilityHandler

## getHelpText()

String juce::Component::getHelpText | ( |  | ) | const

inline noexcept

Returns the help text for this component.

See also
  setHelpText

## setHelpText()

void juce::Component::setHelpText | ( | const String & | newHelpText | ) |

Sets the help text for this component.

If this component supports accessibility using the default AccessibilityHandler implementation, this string will be passed to accessibility clients requesting help text and may be read out by a screen reader.

See also
  getHelpText, getAccessibilityHandler

## setAccessible()

void juce::Component::setAccessible | ( | bool | shouldBeAccessible | ) |

Sets whether this component and its children are visible to accessibility clients.

If this flag is set to false then the getAccessibilityHandler() method will return nullptr and this component and its children will not be visible to any accessibility clients.

By default this is set to true.

See also
  isAccessible, getAccessibilityHandler

## isAccessible()

bool juce::Component::isAccessible | ( |  | ) | const

noexcept

Returns true if this component and its children are visible to accessibility clients.

See also
  setAccessible

## getAccessibilityHandler()

AccessibilityHandler * juce::Component::getAccessibilityHandler | ( |  | ) |

Returns the accessibility handler for this component, or nullptr if this component is not accessible.

To customise the accessibility handler for a component, override createAccessibilityHandler().

See also
  setAccessible

References getAccessibilityHandler().

Referenced by getAccessibilityHandler().

## invalidateAccessibilityHandler()

void juce::Component::invalidateAccessibilityHandler | ( |  | ) |

Invalidates the AccessibilityHandler that is currently being used for this component.

Use this to indicate that something in the accessible component has changed and its handler needs to be updated. This will trigger a call to createAccessibilityHandler().

References invalidateAccessibilityHandler().

Referenced by invalidateAccessibilityHandler().

## createAccessibilityHandler()

virtual std::unique_ptr< AccessibilityHandler > juce::Component::createAccessibilityHandler | ( |  | ) |

virtual

Override this method to return a custom AccessibilityHandler for this component.

The default implementation creates and returns a AccessibilityHandler object with an unspecified role, meaning that it will be visible to accessibility clients but without a specific role, action callbacks or interfaces. To control how accessibility clients see and interact with your component subclass AccessibilityHandler, implement the desired behaviours, and return an instance of it from this method in your component subclass.

The accessibility handler you return here is guaranteed to be destroyed before its Component, so it's safe to store and use a reference back to the Component inside the AccessibilityHandler if necessary.

This function should rarely be called directly. If you need to query a component's accessibility handler, it's normally better to call getAccessibilityHandler(). The exception to this rule is derived implementations of createAccessibilityHandler(), which may find it useful to call the base class implementation, and then wrap or modify the result.

See also
  getAccessibilityHandler

Reimplemented in juce::AlertWindow, juce::AndroidViewComponent, juce::BurgerMenuComponent, juce::Button, juce::CallOutBox, juce::CodeEditorComponent, juce::ComboBox, juce::ConcertinaPanel, juce::DialogWindow, juce::DrawableImage, juce::DrawableText, juce::FileBrowserComponent, juce::GroupComponent, juce::HyperlinkButton, juce::ImageComponent, juce::ImagePreviewComponent, juce::Label, juce::ListBox, juce::MenuBarComponent, juce::NSViewComponent, juce::ProgressBar, juce::ScrollBar, juce::SidePanel, juce::Slider, juce::TabbedButtonBar, juce::TabbedComponent, juce::TableHeaderComponent, juce::TableListBox, juce::TextEditor, juce::ToggleButton, juce::Toolbar, juce::ToolbarItemComponent, juce::ToolbarItemPalette, juce::TooltipWindow, juce::TopLevelWindow, juce::TreeView, and juce::UIViewComponent.

References createAccessibilityHandler(), keyboardFocusContainer, none, and setFocusContainerType().

Referenced by createAccessibilityHandler(), and juce::Viewport::createScrollBarComponent().

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited