public void addTableField ( String fieldLabel , JTable field , List < JButton > buttons ) { validateNotTabbed ( ) ; JScrollPane scrollPane = new JScrollPane ( ) ; scrollPane . setVerticalScrollBarPolicy ( JScrollPane . VERTICAL_SCROLLBAR_AS_NEEDED ) ; scrollPane . setViewportView ( field ) ; field . setFillsViewportHeight ( true ) ; // Tables are a special case - they don't have labels and are accessed via the model if ( this . fieldList . contains ( field ) ) { throw new IllegalArgumentException ( "Field already added: " + field ) ; } if ( buttons == null || buttons . size ( ) == 0 ) { if ( fieldLabel == null ) { this . getMainPanel ( ) . add ( scrollPane , LayoutHelper . getGBC ( 1 , this . fieldList . size ( ) , 1 , fieldWeight , 1.0D , GridBagConstraints . BOTH , new Insets ( 4 , 4 , 4 , 4 ) ) ) ; } else { this . addField ( fieldLabel , field , scrollPane , 1.0D ) ; } } else { JPanel tablePanel = new JPanel ( ) ; tablePanel . setLayout ( new GridBagLayout ( ) ) ; tablePanel . add ( scrollPane , LayoutHelper . getGBC ( 0 , 0 , 1 , 1.0D , 1.0D , GridBagConstraints . BOTH , new Insets ( 4 , 4 , 4 , 4 ) ) ) ; JPanel buttonPanel = new JPanel ( ) ; buttonPanel . setLayout ( new GridBagLayout ( ) ) ; int buttonId = 0 ; for ( JButton button : buttons ) { buttonPanel . add ( button , LayoutHelper . getGBC ( 0 , buttonId ++ , 1 , 0D , 0D , GridBagConstraints . BOTH , new Insets ( 2 , 2 , 2 , 2 ) ) ) ; } // Add spacer to force buttons to the top buttonPanel . add ( new JLabel ( ) , LayoutHelper . getGBC ( 0 , buttonId ++ , 1 , 0D , 1.0D , GridBagConstraints . BOTH , new Insets ( 2 , 2 , 2 , 2 ) ) ) ; tablePanel . add ( buttonPanel , LayoutHelper . getGBC ( 1 , 0 , 1 , 0D , 0D , GridBagConstraints . BOTH , new Insets ( 2 , 2 , 2 , 2 ) ) ) ; if ( fieldLabel == null ) { this . getMainPanel ( ) . add ( tablePanel , LayoutHelper . getGBC ( 1 , this . fieldList . size ( ) , 1 , fieldWeight , 1.0D , GridBagConstraints . BOTH , new Insets ( 4 , 4 , 4 , 4 ) ) ) ; } else { this . addField ( fieldLabel , field , tablePanel , 1.0D ) ; } } this . fieldList . add ( field ) ; }
Add a table field .