• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

jtable

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how do you replace old data in the table with new data
 
keiyia jackson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a simple 'ol table. no models. just a jtable
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would not recommend updating JTable directly because you are breaking the Model/Delegate architecture built into Swing. You're better off updating the table via its model anyway because it's a much cleaner approach. What's the matter, you dont like MVC?
SAF
 
keiyia jackson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i don't know the language and because i am so far in the gui process, i wouldn't want to go back and redo everything just when it is working right.
here's the situation:
i have a table with no data in it when the gui comes up. once the user submits a query, the table should then fill up with the info from the query. everything works except the table does not change. it still had the word no data found. the reason i know it should work is because i have a default query that brings back everything. and i follow the index that shows that everything works properly.
 
keiyia jackson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what's mvc
 
Ranch Hand
Posts: 147
Android Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Model View Controller. Your data is represented in the Model.
Check out this link for How to Use Tables. Especially, look at the end of the page for the links to the examples. You may want to see "SimpleTableDemo" and "TableDemo".
Also, look at the javadoc for JTable...it shows a quick way to set up a table model for your table.
[This message has been edited by Glen Tanner (edited July 27, 2001).]
 
keiyia jackson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I live on that page.
 
keiyia jackson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, i have gone everywhere. i really don't understand how to get new data in the table. someone, anyone please help me. i have just today to figure this out. it will would help if you could show me how to convert my simple jtable to an abtract table (i think that's what i want to use). all i know is jtable.
 
Glen Tanner
Ranch Hand
Posts: 147
Android Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Post your code, I'd be happy to try to help.
[This message has been edited by Glen Tanner (edited July 30, 2001).]
 
keiyia jackson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't try to debug it. It is on a shared net server and can be debug only on my network.

[code]
ort javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import javax.swing.table.DefaultTableModel.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import sharednet.*;
import sharednet.immaccs.*;
import sharednet.immaccs.SNReflection;
import query_c.SNQuery_cPackage.*;
import sharednet.ConnectionManagement.*;
import sharednet_c.SNBase_cPackage.eClassId;
import sharednet_c.*;
import sharednet.query.*;
import sharednet.filter.ClientIDFilter;

public class FirstFrame extends JFrame
{
//mine
Container contentPane, NewcontentPane;
JTextArea output;
JScrollPane tablePane;
JDialog helpDialog, refreshDialog, newDialog, tableDialog;
JMenuBar menuBar;
JMenu fileMenu, editMenu, helpMenu, viewMenu, submenu;
JMenuItem ExitmenuItem, menuItem, NewmenuItem, RefreshmenuItem;
JCheckBoxMenuItem RefNamecbMenuItem, OwnercbMenuItem,
ObjectcbMenuItem, ClassIDcbMenuItem;
JRadioButtonMenuItem rbMenuItem;
JList newList;
MenuListener menuListener, RefreshmenuListener,
ObjectmenuListener;
MenuListener OwnermenuListener, ReferencemenuListener,
ClassIDmenuListener;
QueryListener queryListener;
JLabel newLabel, label, tableLabel;
JButton newButton, button, tableButton;
CloseHelpListener closeListener, NewcloseListener,
TablecloseListener;
String text;
JOptionPane NewoptionPane;
JTable defaultTable;
TablePopup tablePopup;
ListSelectionModel lsm;
int selectedRow, numColumns;
private boolean ALLOW_COLUMN_SELECTION= false;
private boolean ALLOW_ROW_SELECTION= true;
//SNBase Platform;
SNBase[] resultObjects = null;
JList list;
JTable table;
SNAPI snapi = null;
String appName = "QueryDriver";
String userName = "QueryDriver";
eClassId classId = eClassId.SNBase_;
String queryString = "1==1";
eOrderBy orderBy = eOrderBy.LOCATION;
String server = "";
SNQuery snquery = null;
Object[][] tabledata;
Object[] objects;
int temp=1;
static final String columnheaders[]= new String []{ "Object Name",
"Reference", "ClassId", "Owner" };

public FirstFrame()
{
//super(new BorderLayout()); //theirs

//mine
setTitle ("Object Viewer");
setSize (328,920);

addWindowListener (new WindowAdapter ()
{//b/g window listener
public void windowActivated (WindowEvent e)
{

}
public void windowClosed (WindowEvent e)
{
//System.out.println ("Window Closed.");
System.exit (0);
}
public void windowClosing (WindowEvent e)
{
//System.out.println ("Window Closing.");
System.exit (0);
}
public void windowDeactivated (WindowEvent e)
{
//System.out.println ("Window Deactivated");
}
public void windowDeiconified (WindowEvent e)
{
//System.out.println ("Window Deiconified.");
}
public void windowIconified (WindowEvent e)
{
//System.out.println ("Window Iconified.");
}
public void windowOpened (WindowEvent e)
{
//System.out.println ("Window Opened.");
}
});//end of window listener

//Create the menu bar.
menuBar = new JMenuBar();
setJMenuBar(menuBar);

//Build the first menu.
fileMenu = new JMenu("File");
fileMenu.setMnemonic(KeyEvent.VK_F);
menuBar.add(fileMenu);
//JMenuItems
NewmenuItem = new JMenuItem("New Query",
KeyEvent.VK_N);
NewmenuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_1, ActionEvent.ALT_MASK));
fileMenu.add(NewmenuItem);
queryListener= new QueryListener();
NewmenuItem.addActionListener (queryListener);
NewmenuItem.setActionCommand("new");

ExitmenuItem = new JMenuItem("Exit", KeyEvent.VK_X);
ExitmenuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_F4, ActionEvent.ALT_MASK));
fileMenu.add(ExitmenuItem);
menuListener= new MenuListener();
ExitmenuItem.addActionListener (menuListener);
ExitmenuItem.setActionCommand("exit");


//Build the second menu.
editMenu = new JMenu("Edit");
editMenu.setMnemonic(KeyEvent.VK_E);
menuBar.add(editMenu);

//JMenuItems
RefreshmenuItem = new JMenuItem("Refresh",
KeyEvent.VK_R);
RefreshmenuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_2, ActionEvent.ALT_MASK));
editMenu.add(RefreshmenuItem);
RefreshmenuListener= new MenuListener();
RefreshmenuItem.addActionListener (RefreshmenuListener);
RefreshmenuItem.setActionCommand("refresh");
refreshDialog = new JDialog(this, "Refresh");
refreshDialog.setBackground(Color.gray);
refreshDialog.setSize(250, 100);
// "text" of refresh dialog box
label = new JLabel("Version 1.0 "+
"Created by Keiyia Jackson");
refreshDialog.getContentPane().add(label, "North");
// button to close help dialog box
button = new JButton("click when done reading");
refreshDialog.getContentPane().add(button, "South");
closeListener = new CloseHelpListener();
button.addActionListener(closeListener);

//Build the third menu.
viewMenu = new JMenu("View");
viewMenu.setMnemonic(KeyEvent.VK_V);
menuBar.add(viewMenu);
//a group of radio button menu items
viewMenu.addSeparator();
//Group group = new ButtonGroup();
ObjectcbMenuItem = new JCheckBoxMenuItem("Object Name");
ObjectcbMenuItem.setSelected(true);
ObjectcbMenuItem.setMnemonic(KeyEvent.VK_O);
//group.add(cbMenuItem);
viewMenu.add(ObjectcbMenuItem);
ObjectmenuListener= new MenuListener();
ObjectcbMenuItem.addActionListener (ObjectmenuListener);
ObjectcbMenuItem.setState(false);
ObjectcbMenuItem.setActionCommand("ObjName");


RefNamecbMenuItem = new JCheckBoxMenuItem
("Reference Name");
RefNamecbMenuItem.setMnemonic(KeyEvent.VK_C);
//group.add(cbMenuItem);
viewMenu.add(RefNamecbMenuItem);
ReferencemenuListener= new MenuListener();
RefNamecbMenuItem.addActionListener
(ReferencemenuListener);
RefNamecbMenuItem.setActionCommand("RefName");

ClassIDcbMenuItem = new JCheckBoxMenuItem("Class ID");
ClassIDcbMenuItem.setMnemonic(KeyEvent.VK_C);
//group.add(cbMenuItem);
viewMenu.add(ClassIDcbMenuItem);
ClassIDmenuListener= new MenuListener();
ClassIDcbMenuItem.addActionListener (ClassIDmenuListener);
ClassIDcbMenuItem.setActionCommand("ClassID");

OwnercbMenuItem = new JCheckBoxMenuItem("Owner");
OwnercbMenuItem.setMnemonic(KeyEvent.VK_W);
//group.add(cbMenuItem);
viewMenu.add(OwnercbMenuItem);
OwnermenuListener= new MenuListener();
OwnercbMenuItem.addActionListener (OwnermenuListener);
OwnercbMenuItem.setActionCommand("Owner");

//Build the fourth menu.
helpMenu = new JMenu("Help");
helpMenu.setMnemonic(KeyEvent.VK_H);
menuBar.add(helpMenu);
//menuBar.setHelpMenu(menu);
menuListener= new MenuListener();

menuItem = new JMenuItem("About...", KeyEvent.VK_H);

helpMenu.add(menuItem);
menuListener= new MenuListener();
menuItem.addActionListener (menuListener);
menuItem.setActionCommand("help");

helpDialog = new JDialog(this, "Help");
helpDialog.setBackground(Color.gray);
helpDialog.setSize(250, 100);
// "text" of help dialog box
label = new JLabel("Version 1.0 "+
"Created by Keiyia Jackson");
helpDialog.getContentPane().add(label, "North");
// button to close help dialog box
button = new JButton("click when done reading");
helpDialog.getContentPane().add(button, "South");
closeListener = new CloseHelpListener();
button.addActionListener(closeListener);

for (int i=0;i<213 ;i++ )
{

tabledata = new Object [213][4];
tabledata[i][0] = new String(" ");
tabledata[i][1] = new String(" ");
tabledata[i][2] = new String(" ");
tabledata[i][3] = new String(" ");
}

defaultTable = new JTable(tabledata,
columnheaders);


tablePane = new JScrollPane(defaultTable,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

defaultTable.setPreferredScrollableViewportSize
(new java.awt.Dimension(750, 950));

tablePopup = new TablePopup(defaultTable);
defaultTable.addMouseListener(new MouseAdapter()
{
public void mouseReleased (MouseEvent e)
{
if (e.isPopupTrigger())
tablePopup.show (e.getComponent(),
e.getX(), e.getY());
}
});


defaultTable.setVisible(true);


defaultTable.setSelectionMode
(ListSelectionModel.SINGLE_SELECTION);
if (ALLOW_ROW_SELECTION)
{
ListSelectionModel row =defaultTable.getSelectionModel();
row.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
//Ignore extra messages.
if (e.getValueIsAdjusting())
return;
lsm =(ListSelectionModel)e.getSource();
if (lsm.isSelectionEmpty())
{
output.append("No rows are selected.");
output.append("\n");
}
else
{
selectedRow = lsm.getMinSelectionIndex();
if (resultObjects!=null)
{

try
{
output.setText(SNReflection.print(resultObjects[selectedRow], false));

}
catch (Exception exc)
{
exc.printStackTrace();
System.out.print(exc);
output.setText("Unable to display object.");
}
}
else
output.setText("No data found");
}
}
});
}
else
{
defaultTable.setRowSelectionAllowed(false);
}
if (ALLOW_COLUMN_SELECTION)
{ // false by default
if (ALLOW_ROW_SELECTION)
{
//We allow both row and column selection, which
//implies that we *really* want to allow individual
//cell selection.
defaultTable.setCellSelectionEnabled(true);
}
defaultTable.setColumnSelectionAllowed(true);
ListSelectionModel colSM =
defaultTable.getColumnModel().getSelectionModel();
colSM.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
//Ignore extra messages.
if (e.getValueIsAdjusting())
return;
lsm = (ListSelectionModel)e.getSource();
if (lsm.isSelectionEmpty())
{
output.append("No columns are selected.");
//output.append(SNReflection.print("No columns are selected."));

output.append("\n");
}
else
{
int selectedCol = lsm.getMinSelectionIndex();
output.append("Column " + selectedCol
+ " is now selected.");
output.append("\n");
}
}
});
}

//Build output area.
output = new JTextArea (1,10);
output.setEditable(false);
JScrollPane outputPane = new JScrollPane(output,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
//Do the layout.
JSplitPane splitPane = new JSplitPane
(JSplitPane.HORIZONTAL_SPLIT);
getContentPane().add(splitPane, BorderLayout.CENTER);

//left half
JPanel leftHalf = new JPanel();
leftHalf.setLayout(new BoxLayout
(leftHalf, BoxLayout.X_AXIS));
JPanel tableContainer = new JPanel(new GridLayout(1,1));
tableContainer.add(tablePane);
tablePane.setPreferredSize(new java.awt.Dimension(970, 235));

leftHalf.setBorder(BorderFactory.createEmptyBorder(5,5,0,5));
leftHalf.add(tableContainer);

leftHalf.add(tablePane, BorderLayout.CENTER);
leftHalf.setPreferredSize(new java.awt.Dimension(400,500 ));
splitPane.add(leftHalf);

//right half
JPanel rightHalf = new JPanel(new BorderLayout());
rightHalf.add(outputPane, BorderLayout.CENTER);
rightHalf.setPreferredSize(new java.awt.Dimension(450, 500));
splitPane.add(rightHalf);
//popup dialog for selected cell
/**********************
tableDialog = new JDialog(this, "Row" );
tableDialog.setBackground(Color.gray);
tableDialog.setSize(250, 100);
******************************/
// Find a server connection.
ConnectionObject connectionObject = null;
ConnectionManagement connectionMgr = new ConnectionManagement();
try
{
connectionMgr.initialize();
}
catch (Exception ex)
{
ex.printStackTrace();
System.out.println("Did not initialize");
}
connectionObject = connectionMgr.getDefaultConnection();
try
{
snapi = new SNAPI(userName, appName, connectionObject);
snquery = new SNQuery (snapi, connectionObject);
}
catch (Exception ex)
{
ex.printStackTrace();
System.out.println("Query was not submitted");
}


}

private class QueryListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
String cmd=event.getActionCommand();
if (cmd.equals("new"))
{

String request = JOptionPane.showInputDialog
( null,"Query:");
if (request!=null)
{
System.out.println( "OK selected" );
try
{
objects = snquery.submitQuery(
classId,
queryString,
orderBy,
new Position(0.d, 0.d, 0.f, 0, 0, "I'm here"),
new Position(0.d, 0.d, 0.f, 0, 0, "No here"));

resultObjects=new SNBase[objects.length];
for (int i=0;i<objects.length ;i++ )>
{
resultObjects[i]=snapi.resolve((String)objects[i]);
}
//SNAPI.resolve(resultObjects);
}
catch (Exception ex)
{
ex.printStackTrace();
System.out.println ("Failed");
}
System.out.println("Ran submitQuery");


System.out.println("Length = " + resultObjects.length);
try
{
for (int i=0; i<resultObjects.length; i++)>
{
//System.out.println("index = " + i);
String name=resultObjects[i].objectName();
System.out.println( name);

tabledata[i][0] = resultObjects[i].objectName();
//tabledata[i][1] = ((IMMACCSObject)resultObjects[i]).referenceName();
tabledata[i][1] = new String ("refrenceName");
tabledata[i][2] = resultObjects[i].classId();
tabledata[i][3] = resultObjects[i].owner();
getContentPane().repaint();
//temp=i;
}


}
catch (Exception exc)
{
exc.printStackTrace();
System.out.println("Error filling in column values.");
}

}
else
System.out.println( "CANCEL selected" );
}

}
};
private class QueryListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
String cmd=event.getActionCommand();
if (cmd.equals("new"))
{

String request = JOptionPane.showInputDialog
( null,"Query:");
if (request!=null)
{
System.out.println( "OK selected" );
try
{
objects = snquery.submitQuery(
classId,
queryString,
orderBy,
new Position(0.d, 0.d, 0.f, 0, 0, "I'm here"),
new Position(0.d, 0.d, 0.f, 0, 0, "No here"));

resultObjects=new SNBase[objects.length];
for (int i=0;i<objects.length ;i++ )>
{
resultObjects[i]=snapi.resolve((String)objects[i]);
}
//SNAPI.resolve(resultObjects);
}
catch (Exception ex)
{
ex.printStackTrace();
System.out.println ("Failed");
}
System.out.println("Ran submitQuery");


System.out.println("Length = " + resultObjects.length);
try
{
for (int i=0; i<resultObjects.length; i++)>
{
//System.out.println("index = " + i);
String name=resultObjects[i].objectName();
System.out.println( name);

tabledata[i][0] = resultObjects[i].objectName();
//tabledata[i][1] = ((IMMACCSObject)resultObjects[i]).referenceName();
tabledata[i][1] = new String ("refrenceName");
tabledata[i][2] = resultObjects[i].classId();
tabledata[i][3] = resultObjects[i].owner();
getContentPane().repaint();
//temp=i;
}


}
catch (Exception exc)
{
exc.printStackTrace();
System.out.println("Error filling in column values.");
}

}
else
System.out.println( "CANCEL selected" );
}

}
};
private class MenuListener implements ActionListener
{//b/g of menulistener
public void actionPerformed(ActionEvent event)
{//b/g of actionperformed
String cmd=event.getActionCommand();
// action command for this action
if (cmd.equals("exit"))
{
System.out.println ("Window Closing.");
System.exit(0);
}
if (cmd.equals("help"))
{
System.out.println ("Help.");
helpDialog.show();
}
/**************************
So far refresh just returns the default query
**************************/
if (cmd.equals("refresh"))
{
//System.out.println ("Refresh.");
//resubmit the query
try
{
objects = snquery.submitQuery(
classId,
queryString,
orderBy,
new Position(0.d, 0.d, 0.f, 0, 0, "I'm here"),
new Position(0.d, 0.d, 0.f, 0, 0, "No here"));
resultObjects=new SNBase[objects.length];
for (int i=0;i<objects.length ;i++ )>
{
resultObjects[i]=snapi.resolve((String)objects[i]);
}
}
catch (Exception ex)
{
ex.printStackTrace();
System.out.println ("Failed");
}
System.out.println("Ran resubmitQuery");
System.out.println("Length = " + resultObjects.length);
try
{
for (int i=0; i<resultObjects.length; i++)>
{
String name=resultObjects[i].objectName();
//System.out.println("Index = " + i);
System.out.println( name);

tabledata[i][0] = resultObjects[i].objectName();
//tabledata[i][1] = ((IMMACCSObject)resultObjects[i]).referenceName();
tabledata[i][1] = new String ("refrenceName");
tabledata[i][2] = resultObjects[i].classId();
tabledata[i][3] = resultObjects[i].owner();
getContentPane().repaint();
//defaultTable.newDataAvailable();
//defaultTable.newRowsAdded(null);
}
}
catch (Exception exc)
{
exc.printStackTrace();
System.out.println("Error filling in column values.");
}
System.out.println("refresh");
}

if (ObjectcbMenuItem.isSelected())
{
//System.out.println (ObjectcbMenuItem.getState());
TableColumn column0=null;
column0=defaultTable.getColumnModel().getColumn(0);
column0.setMaxWidth(500);
column0.setMinWidth(15);
column0.setPreferredWidth(500);
}

else
{
//System.out.println (ObjectcbMenuItem.getState());
TableColumn column0=null;
column0=defaultTable.getColumnModel().getColumn(0);
column0.setMaxWidth(0);
column0.setMinWidth(0);
column0.setPreferredWidth(0);

}

if (RefNamecbMenuItem.isSelected())
{
//System.out.println (RefNamecbMenuItem.getState());
TableColumn column1=null;
column1=defaultTable.getColumnModel().getColumn(1);
column1.setMaxWidth(500);
column1.setMinWidth(15);
column1.setPreferredWidth(500);
}
else
{
//System.out.println (RefNamecbMenuItem.getState());
TableColumn column1=null;
column1=defaultTable.getColumnModel().getColumn(1);
column1.setMaxWidth(0);
column1.setMinWidth(0);
column1.setPreferredWidth(0);

}
if (ClassIDcbMenuItem.isSelected())
{
//System.out.println (ClassIDcbMenuItem.getState());
TableColumn column2=null;
column2=defaultTable.getColumnModel().getColumn(2);
column2.setMaxWidth(500);
column2.setMinWidth(15);
column2.setPreferredWidth(500);
}
else
{
//System.out.println (ClassIDcbMenuItem.getState());
TableColumn column2=null;
column2=defaultTable.getColumnModel().getColumn(2);
column2.setMaxWidth(0);
column2.setMinWidth(0);
column2.setPreferredWidth(0);

}
if (OwnercbMenuItem.isSelected())
{
//System.out.println (OwnercbMenuItem.getState());
TableColumn column3=null;
column3=defaultTable.getColumnModel().getColumn(3);
column3.setMaxWidth(500);
column3.setMinWidth(15);
column3.setPreferredWidth(500);
}
else
{
//System.out.println (OwnercbMenuItem.getState());
TableColumn column3=null;
column3=defaultTable.getColumnModel().getColumn(3);
column3.setMaxWidth(0);
column3.setMinWidth(0);
column3.setPreferredWidth(0);

}
}//end of actionperformed
}//end of menulistener

//close the help box
private class CloseHelpListener implements ActionListener
{//b/g of CloseHelpListener
public void actionPerformed(ActionEvent event)
{
helpDialog.setVisible(false);
refreshDialog.setVisible (false);
tableDialog.setVisible(false);
}
}//end of CloseHelpListener
class TablePopup extends JPopupMenu
{//b/g of TablePopup
public TablePopup(JTable defaultTable)
{
JMenuItem listAttribute = new JMenuItem
("List Attributes");

listAttribute.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
System.out.println("List Attributes");
tableDialog.setVisible (true);
}
});

add(listAttribute);
add(new JSeparator());

}
} //end of TablePopup
}
[code]
 
keiyia jackson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i hava added this class to my code. can anyone help me impliment the changes

[code]
public class MyTableModel extends AbstractTableModel
{
/**
* An array of strings with size 4, to store column names.
*/
protected String[] columnNames = new String[4];

/**
* Initializing the size of columns to be equal to 4.
*/
protected int numColumns = 4;

/**
* A vector to store the data which is initialy
* null.
*/
public Vector rowData = null;

/**
* Number pf rows in the tables are initially zero.
*/
protected int numRows = 0;

/**
* Constructing a MyTableModel with the supplied column names.
* @param names[], array of coulmn names.
*/
public MyTableModel(String[] names)
{
rowData = new Vector();
columnNames = names;
}

/**
* To get number of total columns.
* @return numColumns-Number of columns in the table.
*/

public int getColumnCount()
{
return numColumns;
}

/**
* To get the specified column name.
* @param col - column number
* @return column name
*/
public String getColumnName(int col)
{
return columnNames[col].toString();
}

/**
* To get number of total rows.
* @return numRows- Number of Rows in the table
*/
public int getRowCount()
{
int x = 0;
if(numRows == 0)
{
return x;
}
else
return numRows;
}

/**
* To get the value at the specified row and column of the
* table.
* @param row- the index of the row.
* @param col-the index of the column.
* @ return Object- that contains the table data at the
* specified row and column.
*/
public Object getValueAt(int row, int col)
{
if(numRows == 0)
{
return null;
}
else
return ((Vector)rowData.elementAt(row)).elementAt(col);
}

/**
* making the cell of the table non editable, so that the entered data
* remains same.
* @param row- the index of the row.
* @param col-the index of the column.
* @return boolean-false.
*/
public boolean isCellEditable(int row, int col)
{
return false;
}

/**
* To set the value of the table at the specified row and the column.
* @param row- the index of the row.
* @param col-the index of the column.
*/
public void setValueAt(Object value, int row, int col)
{
Vector d = (Vector)rowData.elementAt(row);
d.setElementAt(value, col);
fireTableCellUpdated(row, col);
}

/**
* To notify the JTable that a new row is inserted.
*/
public void tableValueChanged()
{
numRows = rowData.size();
fireTableRowsInserted(numRows-1, numRows-1);
}
}
[code]
 
We don't have time to be charming! Quick, read this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic