question: private void updateLegends ( ) { if ( m_span == null ) { m_span = new JPanel ( ) ; } JPanel padder = new JPanel ( ) ; JPanel padd2 = new JPanel ( ) ; m_span . setPreferredSize ( new Dimension ( m_span . getPreferredSize ( ) . width , ( m_plots . size ( ) + 1 ) * 20 ) ) ; m_span . setMaximumSize ( new Dimension ( m_span . getPreferredSize ( ) . width , ( m_plots . size ( ) + 1 ) * 20 ) ) ; LegendEntry tmp ; GridBagLayout gb = new GridBagLayout ( ) ; GridBagLayout gb2 = new GridBagLayout ( ) ; GridBagConstraints constraints = new GridBagConstraints ( ) ; m_span . removeAll ( ) ; padder . setLayout ( gb ) ; m_span . setLayout ( gb2 ) ; constraints . anchor = GridBagConstraints . CENTER ; constraints . gridx = 0 ; constraints . gridy = 0 ; constraints . weightx = 5 ; constraints . fill = GridBagConstraints . HORIZONTAL ; constraints . gridwidth = 1 ; constraints . gridheight = 1 ; constraints . insets = new Insets ( 0 , 0 , 0 , 0 ) ; padder . add ( m_span , constraints ) ; constraints . gridx = 0 ; constraints . gridy = 1 ; constraints . weightx = 5 ; constraints . fill = GridBagConstraints . BOTH ; constraints . gridwidth = 1 ; constraints . gridheight = 1 ; constraints . weighty = 5 ; constraints . insets = new Insets ( 0 , 0 , 0 , 0 ) ; padder . add ( padd2 , constraints ) ; constraints . weighty = 0 ; setViewportView ( padder ) ; constraints . anchor = GridBagConstraints . CENTER ; constraints . gridx = 0 ; constraints . gridy = 0 ; constraints . weightx = 5 ; constraints . fill = GridBagConstraints . HORIZONTAL ; constraints . gridwidth = 1 ; constraints . gridheight = 1 ; constraints . weighty = 5 ; constraints . insets = new Insets ( 2 , 4 , 2 , 4 ) ; for ( int i = 0 ; i < m_plots . size ( ) ; i ++ ) { tmp = new LegendEntry ( m_plots . get ( i ) , i ) ; constraints . gridy = i ; m_span . add ( tmp , constraints ) ; } }
target:  Redraw the panel with the legend entries