Skip to main content

Alert

Open in ChatGPT
Shadow dwc-alert 25.00
Java API

The Alert component in webforJ provides contextual feedback messages for users. It's a versatile way to display important information, warnings, or notifications in your app.

Alerts help draw attention to key information without disrupting the user's workflow. They're perfect for system messages, form validation feedback, or status updates that need to be clearly visible but not intrusive.

Creating alerts

An Alert can hold rich content like text, buttons, and other components. Set a theme to visually distinguish the type of message being displayed.

Show Code

Dismissing alerts

If you’d like to give users the option to dismiss the Alert, you can make it closable by calling the setClosable() method.

Alert alert = new Alert("Heads up! This alert can be dismissed.");
closableAlert.setClosable(true);

Alerts often do more than display messages—they can trigger follow-up actions when dismissed. Use the AlertCloseEvent to handle these cases and respond when the user dismisses the Alert.

Show Code

Reusable Alert Component

Closing the alert only hides it—it doesn’t destroy the component, so you can reuse it later if needed.

Styling

Themes

The Alert component supports multiple themes to visually distinguish different types of messages—such as success, error, warning, or info. These themes can be applied using the setTheme() method or directly in the constructor.

Show Code

Expanses

The expanse defines the visual size of the Alert component. You can set it using the setExpanse() method or pass it directly to the constructor. The available options come from the Expanse enum: XSMALL, SMALL, MEDIUM, LARGE, and XLARGE.

Show Code

Loading...