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();
}
}
}
****************************************************************************