*
The moose likes Swing / AWT / SWT and the fly likes Trouble with firingTableData. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Trouble with firingTableData." Watch "Trouble with firingTableData." New topic
Author

Trouble with firingTableData.

Rajapragada Dharani
Greenhorn

Joined: Oct 23, 2003
Posts: 15
HI All,
I have 2 very important questions here please give your valuable suggestions.
I'am using jFrame which adds jInternalFrame1 to its desktopPane,This frame has a jTable, and the table data for it comes from an XML file.I'am using DefaultTableModel for this.Now I have added a button for "FILTER" which opens another jInternalFrame2 with some search criteria.When the user enters some data and selects OK this jInternalFrame2 will get disposed and jInternalFrame1 will now show rows with search criteria.
The problem here is:

1)After the disposing of jInternalFrame2, jInternalFrame1 is unable to get focus...I mean the title bar doesn't show that its focused.I have used all possible methods to do so like...
setVisible(true);requestFocus();moveToFront();setFocusable(true);

2)This a very important issue, though i filter my data its not reflected in the jTable of jInternalrame1 i wish to show.I have used methods:
TableModel.removeRow();deviceTableModel.fireTableDataChanged();
But it sure is getting removed from TableModel...this i observed from printing rowcount.

I dont know if i'am right but think as jInternalFrame1 is not showing focus i'am unable to see the filtered table data.

Can any one please give your valuable suggestions here.
Thanks in advance.
[ December 16, 2004: Message edited by: Rajapragada Dharani ]
Rajapragada Dharani
Greenhorn

Joined: Oct 23, 2003
Posts: 15
HI All,
Actually I was trying out with different ways.But even after lot of toiling I'am unable clear some stuffs.This thing is an important project for me and I'am new to swings, so please excuse me if my code looks silly.And help me out asap.

The design of my app is that there is a myMainClass which extends a frame and has a tool bar in the top and left tree and right work space to show internal frames to the center.
when the user clicks on some node in the left tree myInternalFrame1 is shown
this has a JTable and has an option of filtering on selection of which opens another jInternalFrame2.
Once the user says ok in this jInternalFrame2 its closed and the filtered data is shown in jInternalFrame1.
which is not happening.I can see that the data is getting filtered as per desired but jInterFrame1 is not showing the same which holds the JTable.


public class myTableModel extends AbstractTableModel {

private Vector datalist;
private String[] columns = {"Hostname", "Serial Number","Registration"};

public myTableModel() {
}

public myTableModel(Vector l) {
datalist = l;
}

public String getColumnName(int col) {
return columns[col];
}

public int getColumnCount() {
return columns.length;
}


public int getRowCount() {
return datalist.size();
}


public Object getValueAt(int row, int col) {

Vector rowList = (Vector)datalist.get(row);

if(rowList.firstElement()!=null) {

switch (col) {

case 0:
return (String) rowList.elementAt(0);
case 1:
return (String) rowList.elementAt(1);
case 2:
return (String) rowList.elementAt(2);
default:
return null;
}
}else return null;

}



// This one method decides exactly which cells are editable.
public boolean isCellEditable(int row, int col) {
switch (col) {

case 0: //Hostname
return false;
case 1: //Product Family
return false;
case 2: //Serial Number
return false;
default:
return false;
}
}


public Class getColumnClass(int col) {
switch (col) {

case 0: //Hostname
return String.class;
case 1: //Product Family
return String.class;
case 2: //Serial Number
return String.class;
default:
return null;
}
}

public void removeRowAt(int row) {

ArrayList removeRow = (ArrayList) datalist.remove(row);
fireTableDataChanged();

}

}

public class myMainClass extends JFrame {

myDesktopPane desktopPane = new myDesktopPane();

public myMainClass(){
}

//This frame has a toolbar in the top and left tree and right workspace in the center of the frame
//once the user selects a particular node in tree I'am trying to show internal frame on the desktoppane
//The below code is written in listeners.Which works fine.

{
jInternalFrame1 jIF1 = new jInternalFrame1();
myPanel myP = new myPanel();

jIF1.getContentPane().add(myP.getPanel());

desktopPane.add(jIF1);
}
//This block is implemented when action is performed in myInternalFrame1

else if (event.getSource().equals("filterButton")){

jInternalFrame2 filterFrame = new jInternalFrame2(m_Model);

desktopPane.add(filterFrame);

}

}

****************************************************************************************
public class myPanel extends JPanel implements ActionListener, HyperlinkListener, ListSelectionListener, MouseListener
{

myTableModel myTableModel;
JTable myTable;
JPanel mainPanel = new JPanel(new BorderLayout());
JPanel myPanel = new JPanel(new BorderLayout());
Jpanel actionBarPanel = new JPanel(new FlowLayout());

public myPanel(){

Vector tableData = new Vector();
//this returns all the data to be shown in table
tableData = returnList();

myTableModel = new myTableModel(tableData);
myTable = new JTable(myTableModel);

myTable.setRowSelectionAllowed(true);
myTable.setColumnSelectionAllowed(false);

scrollList = new JScrollPane(myTable); //panelScroller);
myTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ListSelectionModel mySM = myTable.getSelectionModel();
mySM.addListSelectionListener(this);
myTable.addMouseListener(this);

panelList.add(scrollList, BorderLayout.CENTER);

editButton = new JButton("Edit");
editButton.addActionListener(this);
deleteButton = new JButton("Delete");
deleteButton.addActionListener(this);
filterButton = new JButton("Filter");
filterButton.addActionListener(this);

actionBarPanel.add(rowStatus);
actionBarPanel.add(editButton);
actionBarPanel.add(deleteButton);
actionBarPanel.add(filterButton);

mainPanel.add(panelList,BorderLayout.CENTER)
mainPanel.add(actionBarPanel,BorderLayout.PAGE_END)
}

public JPanel getPanel()
{
return this.mainPanel;
}



public void valueChanged(ListSelectionEvent mySelectionEvent)
{
if (mySelectionEvent.getValueIsAdjusting()) return;

ListSelectionModel lsm = (ListSelectionModel)mySelectionEvent.getSource();
//Here i wanted to do same action if selection is not empty.
String hostName = (String)myTableModel.getValueAt(myTable.getSelectedRow(),0);
}

//Used for changing table view according to filter criteria.

public void refreshList(String hostName) {

String searchHostName = hostName;

int rowCount = myTableModel.getRowCount();

for(int i=0;i<rowCount;i++){
myTableModel.removeRowAt(0);
}

//this returns all the data to be shown in table
tableData = returnList();

for (int i = 0; i < tableData.size(); i++) {

if(tableData(i).getHostname().equals(searchHostName)){
myTableModel.addRow(row);
}
}
myTableModel.fireTableDataChanged();
}


else if (event.getSource() == filterButton) {
event.setSource("filterButton");

//Here i'am sending the control to the myMainClass since I found no other way to add the second internal frame to desktoppane.

myMainClass.actionPerformed(event);
}

****************************************************************************************


public class jInternalFrame1 extends JInternalFrame {

public jInternalFrame1()
{

this.setVisible(true);
this.setPreferredSize(new Dimension(740,500));
this.setContentPane(contentPane);
this.setLocation(50, 50);
this.setPreferredSize(new Dimension(750,500));
this.setMinimumSize(new Dimension(750,500));
this.setMaximizable(true);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

}
}
****************************************************************************************

public class jInternalFrame2 extends JInternalFrame {

JPanel filterPanel;
JPanel actionBarPanel;
JPanel mainPanelList;

JLabel lhostName = new JLabel("Host Name :");
JLabel lType = new JLabel("Product Family :");
JLabel lserialNumber = new JLabel("Serial Number :");

JTextField thostName = new JTextField(10);
JTextField tType = new JTextField(10);
JTextField tserialNumber = new JTextField(10);

JButton bOk = new JButton("Ok");
JButton bCancel = new JButton("Cancel");

public jInternalFrame2()
{
this.setVisible(true);
this.setPreferredSize(new Dimension(740,500));
this.setContentPane(contentPane);
this.setLocation(50, 50);
this.setPreferredSize(new Dimension(750,500));
this.setMinimumSize(new Dimension(750,500));
this.setMaximizable(true);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

filterPanel = new JPanel(new GridLayout(7,2));

filterPanel.add(lhostName);
filterPanel.add(thostName);
filterPanel.add(lType);
filterPanel.add(tType);
filterPanel.add(lserialNumber);
filterPanel.add(tserialNumber);

actionBarPanel = new JPanel(new FlowLayout());
bOk.addActionListener(this);
bCancel.addActionListener(this);
actionBarPanel.add(bOk);
actionBarPanel.add(bCancel);

mainPanelList = new JPanel(new BorderLayout());

mainPanelList.add(filterPanel,BorderLayout.CENTER);
mainPanelList.add(actionBarPanel,BorderLayout.PAGE_END);

getContentPane().add(mainPanelList);
}


public void actionPerformed(ActionEvent event) {

String searchHostName = thostName.getText();

if (event.getSource() == bOk) {

myPanel myP = new myPanel();

if(!searchHostName.equals(null))
{
myP.refreshList(searchHostName);
}

this.dispose();

}else if (event.getSource() == bCancel) {
this.dispose();
}
}
}
****************************************************************************
Rajapragada Dharani
Greenhorn

Joined: Oct 23, 2003
Posts: 15
HI,
Sorry for the trouble given in making you read all code.The code is not directly testable.But my real code is very huge and thought i would simplify by giving you only necessary details just to understand what i was trying to do and suggest possible gap.
Well there's some refinement in the approach.I now tracked the problem ..... actually the table data is getting fired....this i understood after giving some sop's.Now the only problem is that....as soon as myInternalFrame2 is disposed my InternalFrame1 is not getting selected.....i..e, its title bar is not highlighted.So i'am unable to see the table data fired......can any one please suggest me how to do this as soon as my interframe is disposed.I'am not getting were exactly to use frame.setSelected(true) or any other practices.

Thanks again in advance.
Rajapragada Dharani
Greenhorn

Joined: Oct 23, 2003
Posts: 15
HI guys,
I got my things right.....thanks all for patient walk thru.I actually removed the second frame and added the filter criteria in the same frame above table.That looks simple and elegant right.Any way I will try the other stuff later and inform if any improvements.

Regards Raja.
 
Don't get me started about those stupid light bulbs.
 
subject: Trouble with firingTableData.
 
Similar Threads
How to set the jInternalFrame to be disable?
JTable question
Wanted: conceptual tutorial on JTable
Extending JTable
Jtable