raghumohan reddy

Greenhorn
+ Follow
since Oct 07, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by raghumohan reddy

Originally posted by Paul Stevens:
Are you putting a different JComboBox in each row of that column or the same JComboBox?


Same JComboBox
19 years ago
hi anandh,
add combobox to itemlistener.
i am sending the code to u.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
import java.net.*;
import java.util.*;
import javax.swing.event.*;
import javax.swing.table.*;
public class AdminEvaluation extends JFrame implements ActionListener,ItemListener
{
JPanel titlepanel,tablepanel,optionpanel,main;
//JLabel lblhead;
JScrollPane scrpanel;
JButton btnback,btnnext;
Vector tablevalues;
public static JTable table ;
JApplet app;
String ideaid;
Container con;
JComboBox comboBox;
public AdminEvaluation()
{

con=getContentPane();
this.app=app;
this.ideaid=ideaid;
main=new JPanel();
main.setSize(300,300);
//JScrollPane scroll = new JScrollPane(main, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
main.setLayout(new BorderLayout());
//main.setBackground(java.awt.Color.white);
//titlepanel=new JPanel();
//titlepanel.setBackground(java.awt.Color.white);
tablepanel=new JPanel();
//tablepanel.setBackground(java.awt.Color.white);
optionpanel=new JPanel();
//optionpanel.setBackground(java.awt.Color.white);

//lblhead=new JLabel("Administrator Evaluation");
//lblhead.setFont(new Font("Serif", Font.BOLD, 25));
//titlepanel.add(lblhead);

String[] colTitles = {"Critera","Marks","Critera Description"};
Object[][] dataEntries ={
{"1. Imp ", "1", "Feasibility and ease of implementation"},
{"2. C&B ", "5", "Cost - benefit ratio "},
{"3. CP ", "6", "Commercial potential"},
{"4. Str ", "3", "Fit with Strategy"},
{"5. SP ", "6", "Social potential"},
{"6. CA ", "2", "Competitive advantage"},
{"7. Nov ", "1", "Novelty"},
{"8. EMS ", "1", "Enhances market share"},
{"9. EF", "1", "Environmetal friendly "},
{"10. EIF ", "1", "Employee interests "},
};
TableModel model = new EditableTableModel(colTitles, dataEntries);
table = new JTable(model);
table.createDefaultColumnsFromModel();
String[] num = {"1","2","3","4","5","6","7","8","9","10"};
comboBox = new JComboBox(num);
comboBox.addItemListener(this);
table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(comboBox));
//table.setSize(50,50);

table.getColumn("Critera").setMaxWidth(75);
table.getColumn("Marks").setMaxWidth(75);
table.getColumn("Critera Description").setMaxWidth(250);

//str=(String)table.getValueAt(0,1);

table.setPreferredScrollableViewportSize(new Dimension(400, 160));

JScrollPane scrollPane = new JScrollPane(table);
tablepanel.add(scrollPane);

//optionpanel.add(new ReviewCon());
btnback=new JButton("Back");
btnback.addActionListener(this);

btnnext=new JButton("Next");
btnnext.addActionListener(this);
optionpanel.add(btnback);
optionpanel.add(btnnext);
JPanel ex=new JPanel();

//main.add(titlepanel,"North");
main.add(tablepanel,"Center");
main.add(optionpanel,"South");
/* int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
scrpanel=new JScrollPane(main,v,h); */
con.add(main, "Center");


}
class EditableTableModel extends AbstractTableModel
{
String colTitles[];
Object dataEntries[][];
int rowCount;
public EditableTableModel(String[] colTitles, Object[][] dataEntries)
{
this.colTitles = colTitles;
this.dataEntries = dataEntries;
}
public int getRowCount(){ return dataEntries.length;}
public int getColumnCount(){return colTitles.length;}
public Object getValueAt(int row, int column){ return dataEntries[row][column];}
public String getColumnName(int column){ return colTitles[column];}
public Class getColumnClass(int column){ return getValueAt(0, column).getClass();}
public boolean isCellEditable(int row, int column){ return true;}
public void setValueAt(Object value, int row, int column){ dataEntries[row][column] = value;}
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==btnnext)
{

// JOptionPane.showMessageDialog(this,str);

//Adding table values into vectors
tablevalues=new Vector();
tablevalues.addElement((String)table.getValueAt(0,1));
tablevalues.addElement((String)table.getValueAt(1,1));
tablevalues.addElement((String)table.getValueAt(2,1));
tablevalues.addElement((String)table.getValueAt(3,1));
tablevalues.addElement((String)table.getValueAt(4,1));
tablevalues.addElement((String)table.getValueAt(5,1));
tablevalues.addElement((String)table.getValueAt(6,1));
tablevalues.addElement((String)table.getValueAt(7,1));
tablevalues.addElement((String)table.getValueAt(8,1));
tablevalues.addElement((String)table.getValueAt(9,1));

}
if(ae.getSource()==btnback)
{


}
}
public void itemStateChanged(ItemEvent ie)
{
if(ie.getSource()==comboBox)
{

int col=table.getSelectedColumn();
int row=table.getSelectedRow();
String rvv=comboBox.getSelectedItem().toString();
String ss=col+"--"+row;
table.setValueAt(rvv,row,2);
table.repaint();
}
}
public static void main(String args[])
{
AdminEvaluation ae=new AdminEvaluation();
ae.setSize(400,400);
ae.setVisible(true);
}
}

if u have any doubt pls mail to my id : raghumohan@passindien.com

Originally posted by anandh:
Hi,
I have a JTable, where on a particular column, I have set the cellEditor as a combobox. When the user clicks on the combo box, I get the ActionEvent for the box, from which I need to popup a dialog box. That dialog box needs to know which row the user clicked on. How does one get that?? Unless the user selects something from the Combobox and table gets updated, thereby generating TableModeListener/tableChanged event, we can get the selected row value. But how does one get the selected row value in the ActionEvent of the combobox?


19 years ago
hello everybody,
im working with JTable in one column i have a JComboBox.
i want to populate different values into JComboBox.
when im trying to do this same values are getting populated into all the JComboBox in that column.
try this out. if anybody get's a solution, pls dont forget to remind me.
with regards,
raghu mohan reddy g
19 years ago