Hi,
Thanks for u r reply.. Can u give me a sample code, its not working..
And the code is............
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
public class wtListTable extends JFrame implements MouseListener
{
public JTable wtListInfo;
public JTabbedPane tabbedPane;
public wtListTable()
{
Object[] columnNames = { "Topic", "Dealer Name", "PlayerName",
"TableName" };
Object[][] data = {
{ "General Topic", "Dealer1", "Player1", "BlackJack10" },
{ "Account Details", "Dealer4", "All on table", "Baccarat1" } };
wtListInfo = new JTable(data, columnNames);
JScrollPane wtListPane = new JScrollPane(wtListInfo);
wtListInfo.setPreferredScrollableViewportSize(new Dimension(500, 160));
JPanel wtListPanel = new JPanel();
wtListPanel.setBorder(new TitledBorder("Waiting List"));
wtListPanel.add(wtListPane);
tabbedPane=new JTabbedPane();
tabbedPane.add(wtListPanel,"WaitingList");
wtListInfo.addMouseListener(this);
add(tabbedPane);
}
public void mousePressed(MouseEvent me){
}
public void mouseClicked(MouseEvent e){
if(wtListInfo.rowAtPoint(e.getPoint()) != -1){
try{
int row=wtListInfo.getEditingRow();
int col=wtListInfo.getEditingColumn();
Object ob=wtListInfo.getValueAt(row,col);
String s1=ob.toString();
tabbedPane.add(new JPanel(),"s1");
e.consume();
}catch(Exception e1){}
}
}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public static void main(String args[]){
wtListTable wt=new wtListTable();
wt.setVisible(true);
}
}
In this when I press on some row on the topic column, I should get a new tab in my tabbed pane .......
Please, help me
Regards,
Sagarika
Message was edited by:
sun_sgrk
Hi
you Add a mouse Listener for you Table And then in use this method.
IT works fine for me
public void mouseClicked(MouseEvent me)
{
Object obj = me.getSource();
if(obj==table)
{
JTable source=(JTable)me.getSource();
int row = source.rowAtPoint(me.getPoint());
int column = source.columnAtPoint(me.getPoint());
System.out.println("Working Point"+row+"and"+column);
Object value = source.getValueAt(row,column);
String selectedvalue=value.toString();
System.out.println("Selected Value"+value);
}
}
Hope it will help you
Jofin
I changed my code of clicked event is like this, even though its not working, please, Help me .........................................
public void mouseClicked(MouseEvent e){
if(e.getClickCount()==2){
Point origin=e.getPoint();
int row=PitBossMainScreen.wtListInfo.rowAtPoint(origin);
int column=PitBossMainScreen.wtListInfo.columnAtPoint(origin);
if((row==-1)|| (column==-1))
return;
else{
//int row=PitBossMainScreen.wtListInfo.getEditingRow();
//int col=PitBossMainScreen.wtListInfo.getEditingColumn();
try{
Object ob=PitBossMainScreen.wtListInfo.getValueAt(row,column);
String s1=ob.toString();
PitBossMainScreen.tabbedPane.add(new JoinTablePanel(),"s1");
}catch(Exception exp){
System.out.println("Exception : "+exp);
}
}
}
}
Its not giving me any exception, but its not creating a new tab on tabbed pane please...........help me any one................
Regards,
Message was edited by:
sun_sgrk
Hi jofin123,
I changed my code like this...................
public void mouseClicked(MouseEvent e){
Object obj=e.getSource();
if(obj==PitBossMainScreen.wtListInfo){
if(e.getClickCount()==2){
Point origin=e.getPoint();
int row=PitBossMainScreen.wtListInfo.rowAtPoint(origin);
int column=PitBossMainScreen.wtListInfo.columnAtPoint(origin);
if((row==-1)|| (column==-1))
return;
else{
//int row=PitBossMainScreen.wtListInfo.getEditingRow();
//int col=PitBossMainScreen.wtListInfo.getEditingColumn();
try{
Object ob=PitBossMainScreen.wtListInfo.getValueAt(row,column);
String s1=ob.toString();
PitBossMainScreen.tabbedPane.add(new JoinTablePanel(),"s1");
}catch(Exception exp){
System.out.println("Exception : "+exp);
}
}
}
}
}
Even though its not working...................any body give me solution.........
Thanks In advance
Hi just execute this and click on the Cells and tell me this is what you wanted. And you find out the Way to read the Row Values and Display it in the Sub Window.
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
public class wtListTable extends JFrame implements MouseListener
{
public JTable wtListInfo;
public JTabbedPane tabbedPane;
public wtListTable()
{
Object[] columnNames = { "Topic", "Dealer Name", "PlayerName","TableName" };
Object[][] data = {{ "General Topic", "Dealer1", "Player1", "BlackJack10" },
{ "Account Details", "Dealer4", "All on table", "Baccarat1" } };
wtListInfo = new JTable(data, columnNames);
wtListInfo.addMouseListener(this);
JScrollPane wtListPane = new JScrollPane(wtListInfo);
wtListInfo.setPreferredScrollableViewportSize(new Dimension(500, 160));
JPanel wtListPanel = new JPanel();
wtListPanel.setBorder(new TitledBorder("Waiting List"));
wtListPanel.add(wtListPane);
tabbedPane=new JTabbedPane();
tabbedPane.add(wtListPanel,"WaitingList");
add(tabbedPane);
}
public void mousePressed(MouseEvent me)
{
}
public void mouseClicked(MouseEvent e)
{
System.out.println("This is WORKING");
subwindow sb = new subwindow();
sb.show();
}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public static void main(String args[]){
wtListTable wt=new wtListTable();
wt.setSize(700,575);
wt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
wt.setVisible(true);
}
}
class subwindow extends JDialog
{
public subwindow()
{
setSize(450,450);
setLocation(50,50);
setTitle("This Works");
}
}
Thank you
Jofin
Hi Jofin,
U r suggestion help me lot.Thannk u very much, I got it like this.......
public void mouseClicked(MouseEvent me){
System.out.println("Clicked ");
Object obj=me.getSource();
if(obj==PitBossMainScreen.wtListInfo){
JTable source=(JTable)me.getSource();
int row = source.rowAtPoint(me.getPoint());
int column = source.columnAtPoint(me.getPoint());
Object ob=PitBossMainScreen.wtListInfo.getValueAt(row,column);
String s1=ob.toString();
PitBossMainScreen.tabbedPane.add(new JoinTablePanel(),s1);
}
}
In this, now I am trying i don't want to generate the event for all the cells only the first column cells, i want to generate this even, so I am trying for that, if u have any idea in that give me.
I am not getting this functionality in double click also if i add a IF condition like this-if(me.getClickCount()==2)
Thanks In Advance
Message was edited by:
sun_sgrk