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(fals e);
scrollpane = null;
} //if
scrollpane = new JScrollPane(dataTable);
scrollpane.setVisible(true );
if (inputPanel == null)
makeGUI();
customerPanel.add(scrollpa ne, BorderLayout.SOUTH);
c.add(tabs);
id.grabFocus();
pack();
repaint();
adupdateTable();
} //try
catch (Exception e)
{
System.out.println("Caught updateTable exception: " + e);
} //catch
} //updatetable
thankxx
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(fals
scrollpane = null;
} //if
scrollpane = new JScrollPane(dataTable);
scrollpane.setVisible(true
if (inputPanel == null)
makeGUI();
customerPanel.add(scrollpa
c.add(tabs);
id.grabFocus();
pack();
repaint();
adupdateTable();
} //try
catch (Exception e)
{
System.out.println("Caught
} //catch
} //updatetable
thankxx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oops - the constants should be the other way around!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thankx grim_toaster and CEHJ for your solutions :)
:-)
I would use subclass of DefaultTableModel rather than AbstractTableModel as the latter contains a few gotchas.