@@ -122,12 +122,14 @@ public class Sheet extends Container {
122122 private static final int DEFAULT_TRANSITION_DURATION = 300 ;
123123 private final Sheet parentSheet ;
124124 private final Label title = new Label ();
125+ private Component titleComponent = title ;
125126 private final EventDispatcher closeListeners = new EventDispatcher ();
126127 private final EventDispatcher backListeners = new EventDispatcher ();
127128 private final Button backButton = new Button (FontImage .MATERIAL_CLOSE );
128129 private final Container commandsContainer = new Container (BoxLayout .x ());
130+ private final Container titleComponentContainer = FlowLayout .encloseCenterMiddle (title );
129131 private final Container titleBar = BorderLayout .center (LayeredLayout .encloseIn (
130- BorderLayout .center (FlowLayout . encloseCenterMiddle ( title ) ),
132+ BorderLayout .center (titleComponentContainer ),
131133 BorderLayout .centerEastWest (null , commandsContainer , backButton )
132134 ));
133135 private final Container contentPane = new Container (BoxLayout .y ());
@@ -399,6 +401,77 @@ public Container getCommandsContainer() {
399401 return commandsContainer ;
400402 }
401403
404+ /// Gets the title text displayed in the default title label.
405+ ///
406+ /// #### Returns
407+ ///
408+ /// The sheet title text.
409+ ///
410+ /// #### Since
411+ ///
412+ /// 8.0
413+ public String getTitle () {
414+ return title .getText ();
415+ }
416+
417+ /// Sets the title text displayed in the default title label.
418+ ///
419+ /// If a custom title component is currently installed via {@link #setTitleComponent(Component)},
420+ /// this method still updates the default title label so that it will be shown if the title
421+ /// component is reset back to null.
422+ ///
423+ /// #### Parameters
424+ ///
425+ /// - `title`: The title text.
426+ ///
427+ /// #### Since
428+ ///
429+ /// 8.0
430+ public void setTitle (String title ) {
431+ this .title .setText (title );
432+ }
433+
434+ /// Gets the component currently used in the center of the title bar.
435+ ///
436+ /// #### Returns
437+ ///
438+ /// The current title component.
439+ ///
440+ /// #### Since
441+ ///
442+ /// 8.0
443+ public Component getTitleComponent () {
444+ return titleComponent ;
445+ }
446+
447+ /// Sets the title component rendered in the center of the title bar.
448+ ///
449+ /// This allows for custom title layouts such as including an image above the title text.
450+ /// If `null` is passed, the default title label is restored.
451+ ///
452+ /// #### Parameters
453+ ///
454+ /// - `cmp`: The component to use for the title area, or `null` to restore the default title label.
455+ ///
456+ /// #### Since
457+ ///
458+ /// 8.0
459+ public void setTitleComponent (Component cmp ) {
460+ if (cmp == null ) {
461+ cmp = title ;
462+ }
463+ if (cmp == titleComponent ) { //NOPMD CompareObjectsWithEquals
464+ return ;
465+ }
466+ if (cmp .getParent () != null ) {
467+ cmp .remove ();
468+ }
469+ titleComponentContainer .removeAll ();
470+ titleComponentContainer .add (cmp );
471+ titleComponent = cmp ;
472+ titleComponentContainer .revalidateLater ();
473+ }
474+
402475 private void initUI () {
403476 setLayout (new BorderLayout ());
404477 contentPane .setSafeArea (true );
@@ -449,7 +522,7 @@ public void show(final int duration) {
449522
450523 // Set the padding in the content pane to match the corner radius
451524 Style s = getStyle ();
452- Style titleParentStyle = title . getParent () .getStyle ();
525+ Style titleParentStyle = titleComponentContainer .getStyle ();
453526 titleParentStyle .setMarginLeft (titleMargin );
454527 titleParentStyle .setMarginRight (titleMargin );
455528 Border border = s .getBorder ();
0 commit comments