Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Vector to String

807607Nov 24 2006 — edited Nov 24 2006
I've found a few example and posts online about this topic and I know there's something in the conversion that I'm doing wrong. I want to take three string constants assign them to a Vector and then place the value in the rows of a table I have created. Below is my AbstractTableModel class and Table class

class FreeRunTableFrame extends JInternalFrame {
// private static final String TITLE =
//private SnapShotFormat frsnf;
private SymbolTableModel frTableModel;
private JTable frTable = new JTable();
private JMenuItem menuItem;
public FreeRunTableFrame(JScrollPane parent) {
frTable.setBounds(0, 0, 200, 380);
parent.setViewportView(frTable);
getContentPane().add(tablePanel(), "Center");
}

private JPanel tablePanel() {
JPanel panel = new JPanel(new BorderLayout());
panel.setBorder(new EmptyBorder(10, 10, 10, 10));

frTable.setRowSelectionAllowed(false);

frTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
JScrollPane scrollPane = new JScrollPane(frTable);
panel.add(scrollPane, BorderLayout.CENTER);

return (panel);
}

private void SetupSymbolFilterTitleBar() {
Vector titleData = new Vector(3, 3);
Vector rowData = new Vector (totalNumSymbols, 3);
String[] title_string = new String[3];
String[] row_string = new String[totalNumSymbols];
title_string[0] = "ID";
title_string[1] = "Symbol";
title_string[2] = "Value";
final String num_const = "0";
final String symbol_const = "1";
final String val_const = "2";
for (int i = 0; i < 3; i++) {
titleData.add(title_string);
}
System.out.println("Total Num Symbols : " + totalNumSymbols + "\n");
MessageFormat msgformat = new MessageFormat ("%s");
msgformat.applyPattern(num_const);
msgformat.applyPattern(symbol_const);
msgformat.applyPattern(val_const);
for (int i = 0; i < totalNumSymbols; i++)
{

row_string[i] = num_const.toString();
row_string[i] = symbol_const.toString();
row_string[i] = val_const.toString();
rowData.add(row_string[i]);
}
titleData.trimToSize();
rowData.trimToSize();
frTableModel = new SymbolTableModel(titleData, rowData);
frTable.setModel(frTableModel);
TableColumn column = null;
for (int i = 0; i < frTable.getColumnCount(); i++) {
column = frTable.getColumnModel().getColumn(i);
column.setMinWidth(60);
column.setResizable(true);
}
}

private void AddSymbol(int number, String symbol, String value) {
String[] row_string = new String[3];
row_string[0] = String.valueOf(number);
row_string[1] = symbol;
row_string[2] = value;
if (number <= totalNumSymbols)
{
//frTable.setModel(frTableModel);
//frTable.setValueAt(row_string[0], number, 0);
//frTable.setValueAt(row_string[1], number, 1);
//frTable.setValueAt(row_string[2], number, 2);
}
}
}

class SymbolTableModel extends AbstractTableModel {
private String[] colNames;
private String[][] rowData;
private int rowCount = 0;
public frTableCellRenderer cell_ren = new frTableCellRenderer();
public SymbolTableModel(Vector header, Vector data) {
colNames = new String[header.size()];
for (int i = 0; i < colNames.length; i++) {
colNames[i] = (String) header.get(i);
}
rowCount = data.size();
System.out.println("RowCount: " + rowCount + "\n");
//String [][] tmp_str = new String[totalNumSymbols][3];
Object [][] data_obj = (Object[][])data.toArray();
for (int i = 0; i < rowCount; i++)
{
for (int x = 0; x < 3; x++)
{
System.out.println("ARRAY: " + data_obj[i][x].toString() + "\n");

}

}
rowData = new String[rowCount][colNames.length];
System.out.println("Before for loop \n");
for (int i = 0; i < rowCount; i++)
{
for (int x = 0; x < 3; x++)
{
//System.out.println("data: " + tmp_str[i][x] + "\n");
//rowData[i][x] = data.get(i).toString();
}

}
}

public int getRowCount() {
return (rowCount);
}

public void setRowCount() {
}

public int getColumnCount() {
return (colNames.length);
}

public Object getValueAt(int row, int column) {
return (rowData[row]);
}

public String getColumnName(int column) {
return (colNames[column]);
}

public void setValueAt(String data, int row, int column) {
System.out.println("In SymbolTableModel's setValueAt\n");
//cell_ren.setValue(data);
//rowData[row][column] = data;
}
public boolean isCellEditable(int row, int col)
{
return true;
}
public Class getColumnClass(int column)
{
return String.class;
}
} // end of SymbolTableModel class

Any help would greatly be appreciated!

Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 22 2006
Added on Nov 24 2006
4 comments
226 views