Link to home
Start Free TrialLog in
Avatar of deena18
deena18

asked on

ScrollBar Problem

hi ...
i have a form that has a table...
i wanted to add scroll bars to that table but i don't really know how to do it.
can someone help me please??

this is my code for creating the table :
final String[] colName = { "CPR", "Name", "Address", "Phone", "Sex", "Date OF Birth" };

TableModel pageModel = new AbstractTableModel()
{
public int getColumnCount()
{
return tableData[0].length;
} //getColumnCount

public int getRowCount()
{
return tableData.length;
} //getRowCount

public Object getValueAt(int row, int col)
{
return tableData[row][col];
} //getValueAt

public String getColumnName(int column)
{
return colName[column];
} //getcolName

public Class getColumnClass(int col)
{
return getValueAt(0, col).getClass();
} //getColumnClass

public boolean isCellEditable(int row, int col)
{
return false;
} //isCellEditable

public void setValueAt(String aValue, int row, int column)
{
tableData[row][column] = aValue;
} //setValueAt
}; //pageModel

//-----------------------------------------------------------------------------------------------------
//Create the JTable from the table model:

dataTable = new JTable(pageModel);

//-----------------------------------------------------------------------------------------------------

if (scrollpane != null)
{
scrollpane.setVisible(false);
scrollpane = null;
} //if

scrollpane = new JScrollPane(dataTable);
scrollpane.setVisible(true);

if (inputPanel == null)
makeGUI();
customerPanel.add(scrollpane, BorderLayout.SOUTH);

c.add(tabs);
id.grabFocus();
pack();
repaint();
adupdateTable();
} //try
catch (Exception e)
{
System.out.println("Caught updateTable exception: " + e);
} //catch
} //updatetable

thankxx

ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
scrollpane = new JScrollPane(dataTable, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

I would use subclass of DefaultTableModel rather than AbstractTableModel as the latter contains a few gotchas.
Oops - the constants should be the other way around!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deena18
deena18

ASKER

thankx grim_toaster and CEHJ for your solutions :)
:-)