The Artima Developer Community
Sponsored Link

Java Answers Forum
ScrollBar problem..

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
nawaray

Posts: 3
Nickname: menwa
Registered: Nov, 2003

ScrollBar problem.. Posted: Nov 28, 2003 5:09 AM
Reply to this message Reply
Advertisement
hi ..
i have a JFrame that has a table ...
i need a vertical scrollbar for that table, because when i add users to the table i want to go down the table by the scrollbar to see their info without the scrollbar i can't see their info..

this is part of the code but when i run my application the scrollbar will not appear...

class UtilityMethods extends JFrame implements ActionListener
{
JPanel customerPanel;
JPanel inputPanel;
JTable dataTable;
static String[][] tableData;
JScrollPane scrollpane;
void makeGUI()
{
c.setLayout(new BorderLayout());
customerPanel = new JPanel(new BorderLayout());
}
Update the customer table from the database:

void updateTable(String userStatus)
{
this.userStatus = userStatus;
updateTable();
}

void updateTable()
{
ResultSet results = null;
ResultSet results1 = null;
try
{
//Get the number of rows in the table so we know how big to make the data array..
int rowNumbers = 0;
int columnCount = 6;

results = stat.executeQuery("SELECT COUNT(*) FROM CUSTOMER ");
if(results.next())
{
rowNumbers = results.getInt(1);
} //if

if(rowNumbers == 0)
rowNumbers = 1;
tableData = new String[rowNumbers][columnCount];

//Initialize the data array with "" so we avoid possibly having nulls in it later..
for(int i =0;i<tableData.length;i++)
{
for(int j=0;j<tableData[0].length;j++)
tableData[j] = "";
}

//Populate the data array with results of the query on the database..
int currentRow = 0;
results1 = stat.executeQuery("SELECT * FROM CUSTOMER ORDER BY ID");
while (results1.next())
{
for(int i = 0; i < columnCount; i++)
tableData[currentRow] = results1.getString(i + 1);
currentRow++;
} //while
//----------------------------------------------------------------------------- ------------------------
//Create the table model:

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
//dataTable.setValue( new JScrollBar(JScrollBar.HORIZONTAL), 2,1 );

}; //pageModel
//Create the JTable from the table model:

dataTable = new JTable(pageModel);


//----------------------------------------------------------------------------- ------------------------
if (scrollpane != null)
{
scrollpane.setVisible(false);
scrollpane = null;
} //if
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


please can someone help
thankx

Topic: dft Previous Topic   Next Topic Topic: static variable

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use