baradhwaj chandramouli

Greenhorn
+ Follow
since Oct 23, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by baradhwaj chandramouli

Hi all,

Need help inTextfields.. Am a newbie in JSP!


I am having two text fields in my page..
My req is this :

If i type some value in the first one the next one should automatically display 12.
Hi ppl,

I ve a button which displays a Jtable . Now i need to display radiobuttons in each row of the table. I ve tried creating the radiobutton but i am unable to display radiobuttons for each row.

And is there any way by which i can resize the radio button?? I ve posted d code below...

<code>

tablebtn.addActionListener(new ActionListener()
{


public void actionPerformed(ActionEvent ae)
{


Vector<Vector<Object>> data = new Vector<Vector<Object>>();
Connection con = null;
String url = "jdbc:mysql://*****/addressbook";
String db = "addressbook";
String driver = "com.mysql.jdbc.Driver";
String user = "******";
String pass = "****";


try
{

Class.forName(driver);
con = DriverManager.getConnection(url, user, pass);
String sql ="SELECT Slno, FIRSTNAME , LASTNAME , ADDRESSLINE1,CITY,STATE,COUNTRY FROM addressbook WHERE Status='ACTIVE'";
PreparedStatement st = con.prepareStatement(sql);
ResultSet rs = st.executeQuery(sql);
java.sql.ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();

System.out.println(sql);
Vector<String> columnNames = new Vector<String>();
System.out.println(columnNames);
p5.removeAll();

for (int i = 1; i <= columns; i++)
{
columnNames.addElement( md.getColumnName(i));

}
System.out.println(columnNames);


while (rs.next())
{
Vector<Object> row = new Vector<Object>(columns);

for (int j = 1; j <= columns; j++)
{
row.addElement(rs.getObject(j));


}

data.addElement(row);
System.out.println(row);
}

rs.close();
p5.setVisible(false);
TableModel model = new DefaultTableModel(data, columnNames);
table.setModel(model);
JRadioButton inter = null;
inter = new JRadioButton();
inter.setSize(1, 1);
inter.setSelected(true);
ActionListener listener = null;
inter.addActionListener(listener);
p5.add(inter);

table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setCellSelectionEnabled(false);
table.setColumnSelectionAllowed(false);
table.setRowSelectionAllowed(true);
int selectedRow = table.getSelectedRow();
table.getSelectionModel().setSelectionInterval(selectedRow, selectedRow);
p5.add(table);
p5.setVisible(true);
table.setVisible(true);
table.revalidate();
table.setEnabled(true);


}

catch(ClassNotFoundException cnfe)
{
cnfe.printStackTrace();
System.out.println("Exception" +cnfe);

}

catch(SQLException sqle)
{
sqle.printStackTrace();
System.out.println("Exception" +sqle);
}
}


});

</code>
15 years ago
Hi,

I ve used a Jtable to display the contents of the DB . Is It possible for me to give radio buttons for all the rows in JTable?

I ve used a button to display the JTable. I ve given my code below for reference

P.S. This s d first time am using Jtable so kindly excuse if i had not used JTables properly..


Thanks in Advance
Baradh

tablebtn.addActionListener(new ActionListener()
{

@SuppressWarnings("deprecation")
public void actionPerformed(ActionEvent ae)
{


Vector<Vector><Object>> data = new Vector<Vector><Object>>();
Connection con = null;
String url = "jdbc:mysql://192.168.1.63:3306/******";
String db = "******";
String driver = "com.mysql.jdbc.Driver";
String user = "****";
String pass = "*****";


try
{

Class.forName(driver);
con = DriverManager.getConnection(url, user, pass);
String sql ="SELECT Slno, FIRSTNAME , LASTNAME ,CITY,STATE,COUNTRY ROM addressbook WHERE Status='ACTIVE'";

PreparedStatement st = con.prepareStatement(sql);
ResultSet rs = st.executeQuery(sql);
java.sql.ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
System.out.println(sql);
Vector<String> columnNames = new Vector<String>();
p5.removeAll();
for (int i = 1; i <= columns; i++)
{
columnNames.addElement( d.getColumnName(i));

}
System.out.println(columnNames);


while (rs.next())
{
Vector<Object> row = new Vector<Object>(columns);

for (int j = 1; j <= columns; j++)
{
row.addElement(rs.getObject(j));
}

data.addElement(row);
System.out.println(row);
}

rs.close();
System.out.println("am still here2");
p5.setVisible(false);
JTable table = new JTable(data, columnNames);
JScrollPane scroll = new JScrollPane (table,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scroll.setVerticalScrollBar(new JScrollBar());
scroll.setHorizontalScrollBar(new JScrollBar());
table.setAutoResizeMode (JTable.AUTO_RESIZE_OFF);

p5.add(table);
p5.add(scroll);
p5.setVisible(true);
table.show(true);
table.revalidate();
//table.repaint();
table.enable(true);
System.out.println("after table");

}

catch(ClassNotFoundException cnfe)
{
cnfe.printStackTrace();
System.out.println("Exception" +cnfe);

}

catch(SQLException sqle)
{
sqle.printStackTrace();
System.out.println("Exception" +sqle);
}
}


});
15 years ago