Skip to content

Instantly share code, notes, and snippets.

@diamondobama
Last active October 18, 2020 20:37
Show Gist options
  • Save diamondobama/941b55f85a828a417fd048623ce78069 to your computer and use it in GitHub Desktop.
Save diamondobama/941b55f85a828a417fd048623ce78069 to your computer and use it in GitHub Desktop.
Add 2 actions to a single container, one action on the entire container and the other on a specific button.
// Create the bottom container and add all components except the close button
Button lead = new Button("");
lead.addActionListener(evt -> System.out.println("Other parts of the container clicked!"));
Label centerLabel = new Label("This is a test label...");
Label westIcon = new Label(myIcon);
Container bottom = BorderLayout.centerEastWest(centerLabel, null, westIcon);
bottom.setLeadComponent(lead);
// Position the close button at the right location
Button closeButton = new Button("Close");
closeButton.addActionListener(evt -> System.out.println("Close button clicked!"));
// Add the close button to the top container (No need to set container lead here)
Container top = FlowLayout.encloseRight(closeButton);
// Use LayeredLayout to wrap the 2 containers, such that the "top" is placed over the "bottom"
Container wrapper = LayeredLayout.encloseIn(bottom, top);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment