craftleft.gif (3002 bytes)QuickTable
Home | API | Tutorial | Download | Support | Contact topblack.gif (108 bytes)


QuickTable User Cp  |  Register  |  Members  |  Search  |  Help
    |- QuickTable Discussion Forums > CellEditor/Renderer Post New Topic   Post A Reply
how to get a combo box based on another column printer friendly version
next newest post | next oldest post
Author Messages
tilh
Private First Class

Gender: Male
Location: Singapore
Registered: Jul 2005
Status: Offline
Posts: 19

Click here to see the profile for tilh Send email to tilh Send private message to tilh Find more posts by tilh Edit or delete this message Reply w/Quote
Posted Friday, August 19, 2005 @ 07:57:13  

I need to have a dynamic combo box that depends on the value of another column in the same row.
A the default combo box does not allow me to do that, I have resorted to build my own
cellComponent.

Unfortunately, I cannot obtain the value of the current row or column from the cellComponent,
getEditingRow always return -1, assuming that it is not editing the table.
GetSelectedRow/Col returns the previous row.

Is it possible to obtain the value of the current row from within the cellcomponent ?

By the way, my table is not tied to the database, it is populated from the InputStream

[Edit by tilh on Friday, August 19, 2005 @ 08:03:48]

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Sunday, August 21, 2005 @ 06:21:38  

CellComponent interface is provided to simplify the coding for TableCellEditor. In some advanced case like yours, you need to create a javax.swing.table.TableCellEditor and assign using column.setCellEditor();

echashnik
Private

Gender: Unspecified
Location:
Registered: Jan 2008
Status: Offline
Posts: 4

Click here to see the profile for echashnik Send email to echashnik Send private message to echashnik Find more posts by echashnik Edit or delete this message Reply w/Quote
Posted Tuesday, June 24, 2008 @ 09:31:19  

You can use code below to add popup listbox:

static JTextField tf = new JTextField();
static String stageID;
static JPopupMenu XGpopup;
static Vector XGpopups, XGvals;
static void setSeparatorPopUp() {
c = XGTable.getColumn (6);
DBTableCellEditor de = (DBTableCellEditor)c.getCellEditor();
tf = (JTextField)de.getComponent();
tf.addMouseListener(new MouseAdapter() {
//int row, clickColumn;
public void mouseReleased(MouseEvent e) {
super.mouseReleased(e); //To change body of overridden methods use File | Settings | File Templates.
if(e.getButton() != MouseEvent.BUTTON3) return;
setXGpopups();
if (XGpopups.size() < 1) return;
XGpopup = new JPopupMenu();
JList jl = new JList(XGpopups);
if (XGpopups.size() < jl.getVisibleRowCount()) jl.setVisibleRowCount(XGpopups.size());
jl.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent evt) {
if (evt.getValueIsAdjusting())
return;
//System.out.println("Selected from " + evt.getFirstIndex());
XGpopup.setVisible(false);
tf.setText(tf.getText() + XGvals.get(evt.getFirstIndex()));
}
});
XGpopup.add(new JScrollPane(jl));
XGpopup.show(e.getComponent(), e.getX(), e.getY());
}
});
c.setCellEditor(new DBTableCellEditor(tf, XGTable) {
public Component getTableCellEditorComponent(JTable table,
Object value, boolean isSelected, int row, int column) {
stageID = XGTable.getValueAt(row, 3).toString();
//IBlog.LOG(stageID + " " + row + " " + column);
tf.setText(value == null ? "" : value.toString());
return tf;
}
});
}

static void setXGpopups() {
XGpopups = new Vector ();
XGvals = new Vector ();
Statement stmt;
ResultSet rs;
try
{
stmt = IBTable.getStatement ();
//IBlog.LOG(stageID);
rs = stmt.executeQuery (IBTable.getQuery("SEPARATOR") + stageID + " )");
while (rs.next ())
{
XGpopups.addElement(rs.getString(1) + " " + rs.getString(2));
XGvals.addElement(rs.getString(1));
}
rs.close ();
} catch (SQLException ex)
{
XGTable.checkError(ex);
}
}

Post New Topic   Post A Reply Jump to:
Contact Us | QuickTable - A Java DBGrid | Privacy Policy All times are GMT -5 Hours.
Welcome to QuickTable Forums, Guest!  
Login
Username :
Password :
In order to fully utilize the abilities of this board, you are required to register as a member. Registration is free, and allows you to do lots of things including turning on or off certain features of this board. Register now!
Powered by CuteCast v2.0 BETA 2
Copyright © 2001-2003 ArtsCore Studios