How to update Jtable based on itemStateChanged in JComboBox?

My bad... I originally posted this topic in the Java Programming forum before I found this forum. My apologies.
Anyway, can someone help me out pls? I need to be able to update my JTable based on the selected item in the combobox. Unfortunately, my JTable doesn't update when I choose another item in the combo box. What am I doing wrong? I've read about TableModels but I'm not quite sure how to use it.
my code:
my_constructor()
JComboBox cbdisease;
cbdisease = new JComboBox();
cbdisease.setEditable(false);
cbdisease.setBounds(30,20,270,25);
add(cbdisease);
cbdisease.addActionListener(this);
cbdisease.addItem("View All");
//aside from "View All" that was previously added to the combo box
//get the values from the database to fill the comboBox
showDiseases();
cbdisease.addItemListener(new ItemListener()
public void itemStateChanged(ItemEvent e)
System.out.println(cbdisease.getSelectedItem());
displayRules();
}// end constructor
method: showDiseases
connect to DB and get D_Description (column in database)
display D_Description in combo box
public void showDiseases()
Connection conn = null;
ResultSet rs = null;
Statement statement = null;
try {
// Connect to DB
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql:///dbused",
"root", "");
// create a statement, execute query
statement = conn.createStatement();
rs = statement.executeQuery("SELECT DISTINCT D_Description FROM disease");
//place D_Description in combo box
while(rs.next())
strDesc = rs.getString("D_Description");
cbdisease.addItem(strDesc);
conn.close();
statement.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}//end catch
}//end showDiseases()
method: displayRules
connect to DB and get the rules depending item selected in the combo box
display the rules in a table
public void displayRules()
Connection conn = null;
ResultSet rs = null;
Statement statement = null;
try {
// Connect to DB
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql:///dbused",
"root", "");
// create a statement, execute query
statement = conn.createStatement();
if(cbdisease.getSelectedItem().equals("View All"))
rs = statement.executeQuery("SELECT D_DiseaseCode, D_Description, D_QuestionCode, D_Question, D_Action, D_NumArrow, D_Arrow FROM Disease ORDER BY D_DiseaseCode, D_QuestionCode");
else //query depends on the item selected in combo box other than "View All"
rs = statement.executeQuery("SELECT D_DiseaseCode, D_Description, D_QuestionCode, D_Question, D_Action, D_NumArrow, D_Arrow FROM Disease WHERE" + " D_Description = '" +cbdisease.getSelectedItem()+ "' ORDER BY D_DiseaseCode, D_QuestionCode");
// Convert the result set into an array of Objects
Object[][] rows = getObjects(rs);
// These are the column headings displayed in the JTable
String[] headings = { "Disease Code", "Description", "Question Code", "Question", "Action", "# of Arrows", "Arrow"};
// Initialize a JTable with the rows of objects and column headings
rulestable = new JTable(rows, headings);
// Add the table to a JScrollPane to make it display nicely
rulesScroll = new JScrollPane(rulestable);
// Add the scroll pane to the container
add(rulesScroll);
rulesScroll.setBounds(30,80,720,380);
conn.close();
statement.close();
} catch (SQLException sqle) {
//sqle.printStackTrace();
System.out.println(sqle.getSQLState());
} catch(Exception e) {
System.err.println("Exception: " + e.getMessage());
}//end displayRules()
method: getObjects
public Object[][] getObjects(ResultSet rs) throws SQLException
// Find out how many columns are in the result set
ResultSetMetaData metaData = rs.getMetaData();
final int colCount = metaData.getColumnCount();
ArrayList rows = new ArrayList();
Object[] row = null;
while (rs.next()) {
// for each row in the result set, put every column into a temporary Object array
row = new Object[colCount];
for (int a = 0; a < colCount; a++)
row[a] = rs.getObject(a+1);
// add the temporary Object array to the array list
rows.add(row);
// convert the array list to objects
return (Object[][])rows.toArray(new Object[0][0]);
}//end getObjects()

Just pass the new data to a new TableModel object's
constructor and then u can use this new table model in
ur JTable constructor. that woud automatically update
the table data.
Cheers!
Asimsir Asim, do you mean inserting
DefaultTableModel rulesmodel = new DefaultTableModel(rows, headings);
to my code?
public void displayRules()
Connection conn = null;
ResultSet rs = null;
Statement statement = null;
try {
// Connect to DB
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql:///dbused",
"root", "");
// create a statement, execute query
statement = conn.createStatement();
if(cbdisease.getSelectedItem().equals("View All"))
rs = statement.executeQuery("SELECT D_DiseaseCode, D_Description, D_QuestionCode, D_Question, D_Action, D_NumArrow, D_Arrow FROM Disease ORDER BY D_DiseaseCode, D_QuestionCode");
else //query depends on the item selected in combo box other than "View All"
rs = statement.executeQuery("SELECT D_DiseaseCode, D_Description, D_QuestionCode, D_Question, D_Action, D_NumArrow, D_Arrow FROM Disease WHERE" + " D_Description = '" +cbdisease.getSelectedItem()+ "' ORDER BY D_DiseaseCode, D_QuestionCode");
// Convert the result set into an array of Objects
Object[][] rows = getObjects(rs);
// These are the column headings displayed in the JTable
String[] headings = { "Disease Code", "Description", "Question Code", "Question", "Action", "# of Arrows", "Arrow"};
// Initialize a JTable with the rows of objects and column headings
rulestable = new JTable(rows, headings);
// Add the table to a JScrollPane to make it display nicely
rulesScroll = new JScrollPane(rulestable);
// Add the scroll pane to the container
add(rulesScroll);
rulesScroll.setBounds(30,80,720,380);
conn.close();
statement.close();
DefaultTableModel rulesmodel = new DefaultTableModel(rows, headings); //like this?
rulestable.setModel(rulesmodel);     
} catch (SQLException sqle) {
//sqle.printStackTrace();
System.out.println(sqle.getSQLState());
} catch(Exception e) {
System.err.println("Exception: " + e.getMessage());
}//end displayRules()

Similar Messages

  • How to update Activity based upon Campaign

    Hi !
    We have created some Campaigns with campaignelements.
    These elements has been "connected" to different BP - based upon roles.
    The corresponding Activities, then has to be updated (Fields: Dates and Status)
    Our task is to create a routine/program, where, based upon Campaign, the corresponding Activities can be updated.
    Could any one please tell us how to do this?
    Regards
    Torben

    Hi Torben,
    I hope I've got your problem correct. I  think that a update of the Activities created during the campaign is not possible. You can try to search for the activities created by the campaign throu the link.
    If I've got you wrong could you describe your business case in more detail please.
    Regards
    Gregor

  • How to update JTable when clicking outside the table?

    Hi
    (Sorry if this has been asked before but I can't seem to see exactly how to do this from previous posts.)
    I have a JTable which sits on a jPanel which itself is part of a frame.
    When I click anywhere outside the table when I'm editing a cell in the table, how do I end the edit mode of the table (so that the cell is updated with the new contents).Currently I can only update a cell's contents during edit when hitting 'enter' or by clicking on another cell within the table.
    It seems that the following code is used in the process but I'm sure that I'm still missing something:
    if(table1.getCellEditor()!=null)
    table1.getCellEditor().stopCellEditing();
    If anyone out there knows how to do this,I'd really appreciate hearing how.
    Thanks a lot
    LGS

    Thanks for your comments but I'm still having problems.
    When I add the following code:
    table1.addFocusListener(new java.awt.event.FocusAdapter()
    public void focusLost(java.awt.event.FocusEvent evt)
    if (table1.getCellEditor() != null)
    table1.getCellEditor().stopCellEditing();
    and then try to edit my table,as soon as I double click on any cell in the table,my setValueAt method in my Table Model is being called before I even edit the cells contents. The above code is in the same method in which I actaully create table1 i.e.createTable().
    Can anyone help?

  • How to update jTable from user input?

    I create one jTable with 2 rows and 3 columns. the jtable colums contains deviceIP and Status. I am getting device IP from user input through jTextfield. so, when user enter IP and click add button, it must added in the jTable rows one by one.
    how can I add it by user enter the IP. Also, I want to update the status column value by "UP" or "DOWN" by just getting string value from other function.
    but, my problem is i need to update the correct IP status value to correct column (ie., I want to put IP 1(row 1) status to column 1 in status column list.
    I don't know about jTable .
    If any one have any examples please give me.

    use
    ((DefaultTableModel)jTable.getModel()).addRow(Object[]);
    Object[] is the array of row data values you want to insert;

  • How to update zfs-based flar?

    Hello!
    I have ZFS-based flash archive (flar file). I need to install to it several additional packages and patches. As I know, it is possible for USF-based flar, but how to do it with ZFS-based one?

    My flash archive knowledge is minimal and I'm not sure how to do this with UFS, but maybe this is what a differential flash archive is?
    If so, ZFS doesn't support this archiving method as described here:
    http://docs.oracle.com/cd/E26505_01/html/E37384/githk.html#scrolltoc
    Only a full initial installation of a ZFS flash archive is supported. You cannot install a differential flash archive of a ZFS root file system or install a hybrid UFS/ZFS archive.
    I think you will need to recreate the flar with the additional components.
    Solaris 10 installation features existed about 10 years before ZFS was created. Getting the basic installation features to work with ZFS was quite an accomplishment. More ZFS installation features have been added since their initial release (Solaris 10 10/08) but not this one.
    Thanks, Cindy

  • How to update multiple based on particular field

    Hi All,
    I have a requirement i.e, i have to update two fields based on another field in OIM 11g
    like
    emp_type cashier_ind store_ind
    H N N
    S Y Y
    here based on emp_type i need update casher_ind and store_ind as shown above, as per my knowledge i think i have to use entity adapter for this is it ryt? can any one help in this

    Use Post Process Event Handlers
    Check Metalink: 1262803.1

  • How to update UDF based upon the row level dimensions.

    Hello Experts,
    I have made 4 new udf at Sales Order.  Its displaying at Righthand side under General Category.
    Now at row level im entering item detail, and other things with 4 profit center vaues.
    So i want that if i enter value in those 4 proft center in row level then it should automatically update those 4 udf with that value.
    It always happen in Add mode of SO, if SO open in update mode then i can update those udf with other values also, which can be differ then row level profit center values.
    If we need to create any trigger or any query for that, then guide me for that.
    Regards,

    Hi Chintesh,
    You can use the option of changing value when the exising column value changes. (also check the option refersh only option)
    pls revert in case more help.
    Regards,
    Datta Kharat

  • How to update multiple calling hours based on business partner

    Hi All,
    please help me in this issue : how to update multiple calling hours based on business partner in SAP CRM.
    Regards,
    Siva kumar.

    Check maintainance view V_TB49, add new scheduling type.

  • How to Update in InDesign based on New XMLElements

    Hi Pals,
    I have InDesign File consist of contents which is based on an XML Hierarchy. And i have a new XML which is having some new XMLElements inserted in the Existing Hierarchy. The new added Elemensts are having same tag name.
    eg:
    InDesign Document XML Structure
    Root
    -<document>
      -<head>
      -<body>
      -<text1>
      -<text2>
      -<text3>
    New XML Structure
    Root
    -<document>
      -<head>
      -<body>
      -<text1>
      -<New>
      -<text2>
      -<New>
      -<text3>
    How to update the new elements in existing InDesign document in Exact place? Expecting favorable reply. Thanks in Advance.
    Regards,
    Subha

    i created below function but it did not update values properly
    Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
    $webURL = "http://tspmcwfe:91" $listName = "Courts"
    Get the SPWeb object and save it to a variable
    $web = Get-SPWeb $webURL
    $list = $web.Lists[$listName] $items = $list.items
    $internal_counter = 1 $flagPID =1 $vPID=0
    Go through all items
    foreach($item in $items)
    $vPID=0
    $PID = $item["ParentID"] -not $null $Pno = $item["Processno"] -match $null $between = $item["ParentID"] -match $vPID
    if($PID -eq $true -and $Pno -eq $true)
    if($between -eq $true) {
    $item["ProcessNo"] = $internal_counter $vPID=$item["ParentID"] } else { $item["ProcessNo"] = $internal_counter
    $vPID=$item["ParentID"] }
    $internal_counter++
    $item.Update()
    $web.Dispose()
    adil

  • How to update a jscrollpane as new tables are added?

    Following is the code of a search form which searches the address based on some search criteria and places the result in the form of table on the panel p3 which has scrollpane sp1. every time the user searches the address a new table adds to the panel but the problem is that as new tables are added to the panel and they get out of the panel the scrollpane does not show the scroll Knob on the scroll bar. please give me the solution that how to update the scrollbar as the new tables are being added to the panel?
    import javax.swing.*;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.border.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.Statement;
    public class Search extends JFrame implements ActionListener
         Container c;
         Toolkit tk;
         JLabel l1; int y=30;
         JPanel p1,p2,p3;     
         JRadioButton rbByName,rbBySirName,rbByID,rbByCity,rbByState;
         JButton btSearch,btView;
         ButtonGroup bgSearch;
         JTextField txtSearch;
         ImageIcon i1;
         Connection con;
         Statement st1;
         PreparedStatement pst1;
         ResultSet rs1;
         Object[][] data;
         public Search()
              super("Search-Address Management System");
              c=getContentPane();
              tk=Toolkit.getDefaultToolkit();
              //setLocation(150,100);
              setSize(1024,768);
              c.setLayout(null);
              setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              defineComponents();
              settingBounds();
              addListeners();
              addComponents();
              JScrollBar sb=new JScrollBar();
              JScrollPane sp1=new JScrollPane(p3,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
              sp1.setBounds(30,300,700,380);
              l1.add(sp1);
              setVisible(true);
         public void defineComponents()
              p1=new JPanel();
              p1.setLayout(null);
              p1.setOpaque(false);
              p2=new JPanel();
              p2.setLayout(null);
              p2.setOpaque(false);
              p3=new JPanel();
              p3.setLayout(null);
              //p3.setOpaque(false);
              i1=new ImageIcon("Images/Main1.jpg");
              l1=new JLabel(i1);
              rbByName=new JRadioButton("First Name");
              rbByName.setOpaque(false);
              rbByName.setForeground(Color.CYAN);
              rbBySirName=new JRadioButton("Last Name");
              rbBySirName.setOpaque(false);
              rbBySirName.setForeground(Color.CYAN);
              rbByState=new JRadioButton("State");
              rbByState.setOpaque(false);
              rbByState.setForeground(Color.CYAN);
              rbByCity=new JRadioButton("City");
              rbByCity.setOpaque(false);
              rbByCity.setForeground(Color.CYAN);
              rbByID=new JRadioButton("ID");
              rbByID.setOpaque(false);
              rbByID.setForeground(Color.CYAN);
              btSearch=new JButton("Search");
              bgSearch=new ButtonGroup();
              txtSearch=new JTextField();
              btSearch=new JButton("Search");
              TitledBorder tb=new TitledBorder("Search Criteria");
              TitledBorder tb1=new TitledBorder("Search");
              p1.setBorder(tb);
              tb.setTitleColor(Color.YELLOW);
              p2.setBorder(tb1);
              tb1.setTitleColor(Color.YELLOW);
         public void settingBounds()
              rbByID.setBounds(20,30,50,20);
              rbByName.setBounds(120,30,100,20);
              rbByState.setBounds(20,70,80,20);
              rbByCity.setBounds(120,70,50,20);
              rbBySirName.setBounds(240,30,100,20);
              p1.setBounds(30,40,400,110);
              p2.setBounds(30,180,400,80);
              //p3.setBounds(30,300,700,380);
              p3.setBackground(Color.BLUE);
              l1.setBounds(0,0,1024,768);
              txtSearch.setBounds(50,210,250,25);
              btSearch.setBounds(320,210,80,25);
              rbByID.setSelected(true);
         public void addListeners()
              btSearch.addActionListener(this);
         public void addComponents()
              p1.add(rbByName);
              p1.add(rbBySirName);
              p1.add(rbByState);
              p1.add(rbByCity);
              p1.add(rbByID);
              c.add(txtSearch);
              c.add(btSearch);
              c.add(p1);
              c.add(p2);
              c.add(l1);
              bgSearch.add(rbByID);
              bgSearch.add(rbByName);
              bgSearch.add(rbBySirName);
              bgSearch.add(rbByCity);
              bgSearch.add(rbByState);
         public void drawtable()
              int i=0,rows=0;
              String[] colNames={"ID","First Name","Last Name","City","State","Operation"};
              String stData=txtSearch.getText();
              try
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   con=DriverManager.getConnection("jdbc:odbc:dsnAddress");
                   if(rbByName.isSelected())
                        pst1=con.prepareStatement("select * from tbaddress where fname=?",ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
                        pst1.setString(1,stData);
                   if(rbByID.isSelected())
                        pst1=con.prepareStatement("select * from tbaddress where ID=?",ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
                        pst1.setString(1,stData);
                   if(rbBySirName.isSelected())
                        pst1=con.prepareStatement("select * from tbaddress where LName=?",ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
                        pst1.setString(1,stData);
                   if(rbByCity.isSelected())
                        pst1=con.prepareStatement("select * from tbaddress where City=?",ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
                        pst1.setString(1,stData);
                   if(rbByState.isSelected())
                        pst1=con.prepareStatement("select * from tbaddress where State=?",ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
                        pst1.setString(1,stData);
                   rs1=pst1.executeQuery();
                   rs1.last();
                   rows=rs1.getRow(); // get no. of rows
                   if(rows==0)
                        JOptionPane.showMessageDialog(this,"***No Record Found***",null,JOptionPane.INFORMATION_MESSAGE,null);
                        return;
                   data=new Object[rows][6]; //     makes an empty two dimensional array of
                                                   //     rows and columns to store data
                   rs1.beforeFirst();
                   while(rs1.next())            //     fills the array with data
                        data[0]=rs1.getString("ID");
                        data[i][1]=rs1.getString("Fname");
                        data[i][2]=rs1.getString("LName");
                        data[i][3]=rs1.getString("City");
                        data[i][4]=rs1.getString("State");
                        data[i][5]="View";
                        i++;
              catch(Exception e)
                   System.out.println("ExceptionSearch="+ e);
              MyTableModel tm=new MyTableModel(data,colNames);
              JTable t1=new JTable(tm)
              // Returning the Class of each column will allow different
    // renderers to be used based on Class
    public Class getColumnClass(int column)
    return getValueAt(0, column).getClass();
              JScrollPane sp=new JScrollPane(t1,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
              sp.setBounds(30,y,600,100);
              p3.add(sp);
              y=y+110;
              ButtonColumn buttonColumn = new ButtonColumn(t1, 5);
         }Edited by: erdeepak on Sep 22, 2008 4:12 AM
    Edited by: erdeepak on Sep 22, 2008 4:24 AM
    Edited by: erdeepak on Sep 22, 2008 4:25 AM
    Edited by: erdeepak on Sep 22, 2008 4:30 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Don't use null layouts. Learn how to use layout managers.
    The basic design of your frame should be something like this:
    JPanel tablePanel = new JPanel( set your desired layout manager here );
    JScrollPane scrollPane = new JScrollPane( tablePanel );Now when you invoke your search code to create a new table the code will be something like:
    JTable table = new JTable(...);
    tablePanel.add( table );
    tablePanel.revalidate();The revalidate() will invoke the layout manager and the new preferred size of the panel will be calculated and then scrollbars will be added if required.
    The key is to use a layout manager and to revalidate the panel containing the tables.

  • Create a JTable based on an ArrayList containing instances of a class.

    I have a class, IncomeBudgetItem, instances of which are contained in an ArrayList. I would like to create a JTable, based on this ArrayList. One variable is a string, while others are type double. Not all variables are to appear in the JTable.
    The internal logic of my program is already working. And my GUI is largely constructed. I'm just not sure how to make them talk to each other. The actually creation of the JTable is my biggest problem right now.

    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.util.ArrayList;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.AbstractTableModel;
    public class TableDemo extends JPanel {
         private boolean DEBUG = false;
         public TableDemo() {
              super(new GridLayout(1, 0));
              ArrayList<MyObject> list = new ArrayList<MyObject>();
              list.add(new MyObject("Kathy", "Smith", "Snowboarding", new Integer(5),
                        new Boolean(false)));
              list.add(new MyObject("John", "Doe", "Rowing", new Integer(3),
                        new Boolean(true)));
              list.add(new MyObject("Sue", "Black", "Knitting", new Integer(2),
                        new Boolean(false)));
              list.add(new MyObject("Jane", "White", "Speed reading",
                        new Integer(20), new Boolean(true)));
              JTable table = new JTable(new MyTableModel(list));
              table.setPreferredScrollableViewportSize(new Dimension(500, 70));
              table.setFillsViewportHeight(true);
              // Create the scroll pane and add the table to it.
              JScrollPane scrollPane = new JScrollPane(table);
              // Add the scroll pane to this panel.
              add(scrollPane);
         class MyObject {
              String firstName;
              String lastName;
              String sport;
              int years;
              boolean isVeg;
              MyObject(String firstName, String lastName, String sport, int years,
                        boolean isVeg) {
                   this.firstName = firstName;
                   this.lastName = lastName;
                   this.sport = sport;
                   this.years = years;
                   this.isVeg = isVeg;
         class MyTableModel extends AbstractTableModel {
              private String[] columnNames = { "First Name", "Last Name", "Sport",
                        "# of Years", "Vegetarian" };
              ArrayList<MyObject> list = null;
              MyTableModel(ArrayList<MyObject> list) {
                   this.list = list;
              public int getColumnCount() {
                   return columnNames.length;
              public int getRowCount() {
                   return list.size();
              public String getColumnName(int col) {
                   return columnNames[col];
              public Object getValueAt(int row, int col) {
                   MyObject object = list.get(row);
                   switch (col) {
                   case 0:
                        return object.firstName;
                   case 1:
                        return object.lastName;
                   case 2:
                        return object.sport;
                   case 3:
                        return object.years;
                   case 4:
                        return object.isVeg;
                   default:
                        return "unknown";
              public Class getColumnClass(int c) {
                   return getValueAt(0, c).getClass();
          * Create the GUI and show it. For thread safety, this method should be
          * invoked from the event-dispatching thread.
         private static void createAndShowGUI() {
              // Create and set up the window.
              JFrame frame = new JFrame("TableDemo");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // Create and set up the content pane.
              TableDemo newContentPane = new TableDemo();
              newContentPane.setOpaque(true); // content panes must be opaque
              frame.setContentPane(newContentPane);
              // Display the window.
              frame.pack();
              frame.setVisible(true);
         public static void main(String[] args) {
              // Schedule a job for the event-dispatching thread:
              // creating and showing this application's GUI.
              javax.swing.SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        createAndShowGUI();
    }

  • How to update ADF VO object to refresh the data in ADF Pivot table

    I need to know how to update the View object so that the date in pivot table is refreshed/updated/filtered.
    here are the steps I performed to create ADF pivot table application using VO at design time.
    1) created a collection in a Data Control (ViewObject in an ApplicationModule) that provides the values I wanted to use for row and column labels as well the cell values (Used the SQL query)
    2) Dragged this collection to the page in which wanted to create the pivot table
    3) In the pivot table data binding editor specified the characteristics of the rows (which attribute(s) should be displayed in header), the columns (likewise) and the cells.
    Now, I have a requirement to update/filter the data in pivot table on click of check box and my question is how to I update the View object so that the date in pivot table is refreshed/updated/filtered.
    I have got this solution from one of the contact in which a WHERE clause on an underlying VO is updated based upon input from a Slider control. In essence, the value of the control is sent to a backing bean, and then the backing bean uses this input to call the "filterVO" method on the corresponding AppModule:
    but, I'm getting "operationBinding" object as NULL in following code. Please let me know what's wrong.
    here is the code
    Our slider component will look like
    <af:selectBooleanCheckbox label="Unit" value="#{PivotTableBean.dataValue}"
    autoSubmit="true" />
    The setDataValue() method in the backing bean will get a handle to AM and will execute the "filterVO" method in that, which takes the NumberRange as the input parameter.
    public void setDataValue(boolean value) {
    DataValue = value;
    BindingContainer bindings = getBindings();
    OperationBinding operationBinding = (OperationBinding)bindings.getOperationBinding("filterVO");
    Object result = operationBinding.execute();
    The filterVO method in the AMImpl.java will get the true or false and set the where Clause for the VO query to show values.
    public void filterVO(boolean value) {
    if (value != null) {
    ViewObjectImpl ibVO = getVO1();
    ibVO.setWhereClause("PRODUCT_TOTAL_REVENUE(+) where rownum < 10");
    ibVO.executeQuery();
    }

    Did you define a filterVO action in your pagedef.xml file?
    You might want to read on how to access service method from a JSF Web Application in the ADF Developer Guide for 10.1.3 chapter 8.5

  • How to update a parent child hierarchy in OBIEE

    Hello All
    Quick question about updating parent child hierarchy in OBIEE.
    As we know, OBIEE 11G allows us to create value based hierarchy by generating table creation script and insert script. In the typical example of employee dimension, the parent child relationship table will be created with the following 4 attributes:
    MEMBER_KEY, ANCESTOR_KEY, DISTANCE, IS_LEAF
    So, what if later in the years some of the employees got promoted, retired or transferred? The value based hierarchy is going to change because person 1 reports to manager 2 now instead of 1. Obviously, the records in employee dimension is going to be updated. When that happens, how to update the parent child relation table with the same information? Do we have to rerun the insert script? How do we keep the history of employee changes and hierarchy changes?
    Please advice
    Thank you

    I guess it will update when the structure changes,Let see the response from other gurus.
    Thanks,

  • CFM /TR - how system calculate amount based on rate FX 60A

    Hi all,
    i need to know how system calculates amount based on rate entered upon creating a contract (t-code TX01).
    steps input:-
    1. header - comp code, product type, trans type
    2. partner
    3. purchase curr & amount (eg. IDR 8,345,545,500)
    4. sale currency only (amount system will auto calculate) USD
    5. rate field = 11.553
    6. spot rate will auto pick up from rate
    7. value date
    8. contract date
    upon TBB1 no error. posting log as follows:-
    FX1000+ : 40 8,345,545,500 IDR bank GL acc
                    50 8,345,545,500 IDR clearing acc
    FX2000- : 40 722370.42 USD clearing acc
                   50 722370.42 USD bank GL acc
    but upon TPM18 error occurred as follows:
    DBT_C009 - GL not maintain in acc symbol 5.3.4
    DBT_E039 - no posting spec assigned to update type
    DBT_B018 : 40 0 USD, 431,977,511 IDR gain/loss
                       50 0 USD, 431,977,511 IDR clearing acc
    so, after maintained DBT_C009 as follows still error for DBT_E039:
    40  0 USD, 38 IDR clearing acc
    50  0 USD, 38 IDR P&L gl acc
    what i don't understand is how system calculate and get DBT_C009 & DBTE039.
    what is the function of TPM18?
    thanks.

    Hello Prarnod,
    I have done the first node only for actuals that come from the integration to the internal order.
    I have tried setting up 2 and 3 even though the 3rd one does not make any sense to me
    Thanks,
    Paul

  • ADF BC: Creating updatable VO based upon DB View with "instead of" trigger

    Hello all,
    I have got an interesting issue. I have an Oracle DB view that is used to hide some complexity in the underlying DB design (it does some unions). This view is updatable because we have created an "instead of" update trigger to update the correct table when a row is updated. This is working fine in SQL.
    Next, we have created an ADF Entity object based upon the view, specifying an appropriate PK for the DB View. Then, we have created an updatable VO based upon the EO. All well and good so far. The issue we have is in trying to commit changes to the DB - because the ADF BC framework is trying to lock the row to update (using SELECT ... FOR UPDATE), it's not working because of ORA-02014 - cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc.
    This leads me to thinking about overridding doSelect() on the EO as hinted here http://radio.weblogs.com/0118231/stories/2005/07/28/differenceBetweenViewObjectSelectAndEntityDoselectMethod.html
    As a temporary test, we have over-ridden the EO's doSelect to call super.doSelect(false) and it does work, although we will have lost update issues as detailed in Steve's article.
    My questions:
    1). Is overriding doSelect() the correct thing here? Perhaps there is a better way of handling this problem? I do have a base EO class from which all of the EO's extend, so adding this behavior should be straightforward.
    2). Does anyone have example doSelect implementation? I am thinking of overriding doSelect for my EO and calling super.doSelect (lock=false), but then I need to deal with some possible exceptions, no?
    Kind regards,
    John

    Hi John,
    I have exactly the same issue as you experienced back in January. I have a complex data modelling requirement which requires the need to pivot rows into columns using ROW_NUMBER() and PARTITION clauses. To hide the complexity from the middle tier, I have created a database view and appropriate INSTEAD OF triggers and mapped my EO to the view. I have overriden the lock() method on the EO implementation class (to avoid ORA-02014) and would like to try the same solution you used with the pl/sql call to lock the record.
    My question is, how did you manage the release of the lock if the transaction was not rolled back or committed by your application i.e. if the user closed the browser for instance.
    In my naivity, I would like to think that the BC4J framework would release any locks for the database session when it found the servlet session to be terminated however my concern is that the lock would persist and cause complications.
    Any assistance greatly appreciated (if you would be willing to supply your lock() method and pl/sql procedure logic I would be even more grateful!).
    Many thanks,
    Dave
    London

Maybe you are looking for