Acho mais fácil mostrar um exemplo.
package guj;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
public class ExemploJScrollPane extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JScrollPane scpMain = null;
private JPanel pnlButtons = null;
private JButton btnOK = null;
private JButton btnCancel = null;
private JPanel pnlInputFields = null;
private JLabel lblName = null;
private JTextField txtName = null;
private JLabel lblAddress = null;
private JTextField txtAddress = null;
private JLabel lblPhone = null;
private JTextField txtPhone = null;
private JLabel lblCountry = null;
private JComboBox cboCountry = null;
private JLabel lblState = null;
private JComboBox cboState = null;
private JSplitPane splMain = null;
private JScrollPane scpTable = null;
private JTable tblTable = null;
private JScrollPane getScpMain() {
if (scpMain == null) {
scpMain = new JScrollPane();
scpMain.setViewportView(getPnlInputFields());
}
return scpMain;
}
private JPanel getPnlButtons() {
if (pnlButtons == null) {
pnlButtons = new JPanel();
pnlButtons.setLayout(new FlowLayout());
pnlButtons.add(getBtnOK(), null);
pnlButtons.add(getBtnCancel(), null);
}
return pnlButtons;
}
private JButton getBtnOK() {
if (btnOK == null) {
btnOK = new JButton();
btnOK.setText("OK");
}
return btnOK;
}
private JButton getBtnCancel() {
if (btnCancel == null) {
btnCancel = new JButton();
btnCancel.setText("Cancel");
}
return btnCancel;
}
private JPanel getPnlInputFields() {
if (pnlInputFields == null) {
lblState = new JLabel();
lblState.setText("State");
lblCountry = new JLabel();
lblCountry.setText("Country");
lblPhone = new JLabel();
lblPhone.setText("Phone");
lblAddress = new JLabel();
lblAddress.setText("Address");
lblName = new JLabel();
lblName.setText("Name");
GridLayout gridLayout = new GridLayout();
gridLayout.setRows(5);
gridLayout.setColumns(2);
pnlInputFields = new JPanel();
pnlInputFields.setLayout(gridLayout);
pnlInputFields.add(lblName, null);
pnlInputFields.add(getTxtName(), null);
pnlInputFields.add(lblAddress, null);
pnlInputFields.add(getTxtAddress(), null);
pnlInputFields.add(lblPhone, null);
pnlInputFields.add(getTxtPhone(), null);
pnlInputFields.add(lblCountry, null);
pnlInputFields.add(getCboCountry(), null);
pnlInputFields.add(lblState, null);
pnlInputFields.add(getCboState(), null);
}
return pnlInputFields;
}
private JTextField getTxtName() {
if (txtName == null) {
txtName = new JTextField();
}
return txtName;
}
private JTextField getTxtAddress() {
if (txtAddress == null) {
txtAddress = new JTextField();
}
return txtAddress;
}
private JTextField getTxtPhone() {
if (txtPhone == null) {
txtPhone = new JTextField();
}
return txtPhone;
}
private JComboBox getCboCountry() {
if (cboCountry == null) {
cboCountry = new JComboBox();
}
return cboCountry;
}
private JComboBox getCboState() {
if (cboState == null) {
cboState = new JComboBox();
}
return cboState;
}
private JSplitPane getSplMain() {
if (splMain == null) {
splMain = new JSplitPane();
splMain.setOrientation(JSplitPane.VERTICAL_SPLIT);
splMain.setResizeWeight(0.5D);
splMain.setBottomComponent(getScpTable());
splMain.setTopComponent(getScpMain());
}
return splMain;
}
private JScrollPane getScpTable() {
if (scpTable == null) {
scpTable = new JScrollPane();
scpTable.setViewportView(getTblTable());
}
return scpTable;
}
private JTable getTblTable() {
if (tblTable == null) {
tblTable = new JTable();
// Só para não deixar em branco - obviamente você não deve
// usar DefaultTableModel em uma aplicação normal.
tblTable.setModel(new DefaultTableModel (new String[][]{
{"Joseph", "8 Mulholland Drive", "555-5555", "123-4567-8"},
{"Apple", "One Infinite Loop", "777-7777", "823-4568-7"},
{"Sun", "4150 Network Circle", "555-9SUN", "123-7777-8"},
{"Oracle", "500 Oracle Parkway", "1-800-ORACLE1", "444-7777-8"},
{"Microsoft", "One Microsoft Way", "882-8080", "444-9999-8"},
{"Red Hat", "1801 Varsity Drive", "754-3700", "333-3339-9"},
},
new String[]{"Name", "Address", "Phone", "SSN"}));
}
return tblTable;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
ExemploJScrollPane thisClass = new ExemploJScrollPane();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
public ExemploJScrollPane() {
super();
initialize();
}
private void initialize() {
this.setSize(300, 293);
this.setContentPane(getJContentPane());
this.setTitle("Teste JScrollPane");
}
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getSplMain(), BorderLayout.CENTER);
jContentPane.add(getPnlButtons(), BorderLayout.SOUTH);
}
return jContentPane;
}
}