public void setListLabels ( String chosenLabel , String sourceLabel ) { if ( chosenLabel != null ) { this . chosenLabel . setText ( chosenLabel ) ; this . chosenLabel . setVisible ( true ) ; } else { this . chosenLabel . setVisible ( false ) ; } if ( sourceLabel != null ) { this . sourceLabel . setText ( sourceLabel ) ; this . sourceLabel . setVisible ( true ) ; } else { this . sourceLabel . setVisible ( false ) ; } Dimension d = chosenList . getPreferredSize ( ) ; Dimension d1 = this . chosenLabel . getPreferredSize ( ) ; Dimension dChosenPanel = chosenPanel . getPreferredSize ( ) ; dChosenPanel . width = Math . max ( d . width , Math . max ( dChosenPanel . width , d1 . width ) ) ; chosenPanel . setPreferredSize ( dChosenPanel ) ; Dimension dSourceList = sourceList . getPreferredSize ( ) ; Dimension dSource = this . sourceLabel . getPreferredSize ( ) ; Dimension dSourcePanel = sourcePanel . getPreferredSize ( ) ; dSourcePanel . width = Math . max ( dSource . width , Math . max ( dSourceList . width , dSourcePanel . width ) ) ; sourcePanel . setPreferredSize ( dSourcePanel ) ; Dimension fullPanelSize = getPreferredSize ( ) ; fullPanelSize . width = dSourcePanel . width + dChosenPanel . width + ( editButton != null ? editButton . getPreferredSize ( ) . width : 0 ) + ( buttonPanel != null ? buttonPanel . getPreferredSize ( ) . width : 0 ) + 20 ; setPreferredSize ( fullPanelSize ) ; }
Add labels on top of the 2 lists . If not present do not show the labels .