JTable and JavaBeans

Hello everybody.
I'm trying to build dinamically a JTable, reading data from a JavaBean.
Everythings works fine, but :
1) if I click outside of my JFrame, when I reselect it the JTable is completely filled with the last row inserted
2)If I scroll the JTable (that is contained in a JScrollPane), rows that momentanely disappear because of the scroll, when I rescroll to the original position I discover that all rows that were "out of sight" as been filled up ith last row's data
3)If I select a column, a row, or simply a cell, when I click on another one this another one's row is filled up with last row data
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.table.AbstractTableModel;
import beans.ArticoloBean;
class TableModel extends AbstractTableModel {
    private String colonna1;
     private String colonna2;
    private ArrayList list;
    private String[] Columns = {
            "Articolo","n�colli","Note"
    Iterator Ilista_articoli;
    ArticoloBean myBean = (ArticoloBean)Ilista_articoli;
    int rowcount=0;
     public TableModel(ArrayList list) {
               this.list=list;
               Ilista_articoli=list.iterator();
               if (Ilista_articoli.hasNext()){
               myBean = (ArticoloBean)Ilista_articoli.next();
    public int getRowCount() {
         return list.size();
     public int getColumnCount() {
        return Columns.length;
    public Object getValueAt(int riga, int colonna) {
         if (rowcount==3){
               if (Ilista_articoli.hasNext()){
                    myBean = (ArticoloBean)Ilista_articoli.next();
                    rowcount=0;
                   rowcount++;
                   if (colonna==0) return myBean.getCodice();
                    if (colonna==1)     return myBean.getColli();
                    if (colonna==2) return myBean.getNote();
               return null;                  
     public boolean isCellEditable(int riga, int colonna) {
        return false;
    public String getColumnName(int colonna) {
        return Columns[colonna];
    }

Well, your TableModel getValueAt(...) method doesn't look correct. Althought I don't know what you bean looks like to it hard to say what the code should be. Why don't you just use the DefaultTableModel and copy the data from the bean to the model?

Similar Messages

  • JTable and clipboard...

    Hi all!
    I'm trying to copy data from JTable to system clipboard. Here's my code that is
    supposed to do that except it doesn't work. Nothing happens. The system is
    Windows, rigth click invokes menu with only one position - COPY, which is served
    by a appopriate ActionListener. I want to copy entire table (all data):
    private class NotEditableTable extends JTable
    NotEditableTable(Object[][] data, Object[] columnNames)
    super(data, columnNames);
    setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    setCellSelectionEnabled(true);
    getTableHeader().setReorderingAllowed(false);
    NotEditableTableEngine nete = new NotEditableTableEngine();
    this.addMouseListener(nete);
    public boolean isCellEditable(int row, int column)
    return false;
    private class NotEditableTableEngine extends MouseAdapter implements ActionListener
    public void mouseReleased(MouseEvent e)
    if (e.isPopupTrigger())
    JPopupMenu menu = new JPopupMenu();
    JMenuItem menuitem = new JMenuItem(Lang.TABLE_COPY, new ImageIcon("res/Copy16.gif"));
    menuitem.addActionListener(this);
    menu.add(menuitem);
    menu.show(NotEditableTable.this, e.getX(), e.getY());
    public void actionPerformed(ActionEvent e)
    TransferHandler th = new TransferHandler(null);
    NotEditableTable.this.setTransferHandler(th);
    Clipboard clip = NotEditableTable.this.getToolkit().getSystemClipboard();
    th.exportToClipboard(NotEditableTable.this, clip, TransferHandler.COPY);
    }

    I also tried the code above with a simple JTextField, both with text selected and not.Did my sample code use the TransferHandler??? The simple way to do it for a JTextField would be
    Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
    StringSelection testData = new StringSelection( textField.getText );
    //StringSelection testData = new StringSelection( textField.getSelectedText );
    c.setContents(testData, testData);
    As for the table I said that the Ctrl-C KeyStroke will invoke the default Action to copy selected data from the JTable to the Clipboard. This can be tested manually by simply using Ctrl-C. If you want to invoke it in your program then you need to get the corresponding Action from the JTable and invoke the ActionPerformed method of the Action. You can try using the
    getActionForKeyStroke(...) method of JComponent to get the Action.

  • JTable and ResultSet TableModel with big resultset

    Hi, I have a question about JTable and a ResultSet TableModel.
    I have to develop a swing JTable application that gets the data from a ResultSetTableModel where the user can update the jtable data.
    The problem is the following:
    the JTable have to contain the whole data of the source database table. Currently I have defined a
    a TYPE_SCROLL_SENSITIVE & CONCUR_UPDATABLE statement.
    The problem is that when I execute the query the whole ResultSet is "downloaded" on the client side application (my jtable) and I could receive (with big resultsets) an "out of memory error"...
    I have investigate about the possibility of load (in the client side) only a small subset of the resultset but with no luck. In the maling lists I see that the only way to load the resultset incrementally is to define a forward only resultset with autocommit off, and using setFetchSize(...). But this solution doesn't solve my problem because if the user scrolls the entire table, the whole resultset will be downloaded...
    In my opinion, there is only one solution:
    - create a small JTable "cache structure" and update the structure with "remote calls" to the server ...
    in other words I have to define on the server side a "servlet environment" that queries the database, creates the resultset and gives to the jtable only the data subsets that it needs... (alternatively I could define an RMI client/server distribuited applications...)
    This is my solution, somebody can help me?
    Are there others solutions for my problem?
    Thanks in advance,
    Stefano

    The database table currently is about 80000 rows but the next year will be 200000 and so on ...
    I know that excel has this limit but my JTable have to display more data than a simple excel work sheet.
    I explain in more detail my solution:
    whith a distribuited TableModel the whole tablemodel data are on the server side and not on the client (jtable).
    The local JTable TableModel gets the values from a local (limited, 1000rows for example) structure, and when the user scroll up and down the jtable the TableModel updates this structure...
    For example: initially the local JTable structure contains the rows from 0 to 1000;
    the user scroll down, when the cell 800 (for example) have to be displayed the method:
    getValueAt(800,...)
    is called.
    This method will update the table structure. Now, for example, the table structure will contain data for example from row 500 to row 1500 (the data from 0 to 499 are deleted)
    In this way the local table model dimension will be indipendent from the real database table dimension ...
    I hope that my solution is more clear now...
    under these conditions the only solutions that can work have to implement a local tablemodel with limited dimension...
    Another solution without servlet and rmi that I have found is the following:
    update the local limited tablemodel structure quering the database server with select .... limit ... offset
    but, the select ... limit ... offset is very dangerous when the offset is high because the database server have to do a sequential scan of all previuous records ...
    with servlet (or RMI) solution instead, the entire resultset is on the server and I have only to request the data from the current resultset from row N to row N+1000 without no queries...
    Thanks

  • How to include a jsp file in servlets and javabeans

    Hi to all..I have a jsp file which contains some database connections and I would like to include in that file in my servlets and javabeans.What coding can i use?Can show me sample coding.

    Hi to all..I have created a javabean storing the
    database connections. How do i include and call that
    bean in my servlet and javabeans?Can pls show me some
    sample coding?I am new to servlets and beans.The same way you do with normal Java Classes. If you are new to Java, I suggest you go to http://java.sun.com/docs/books/tutorial/index.html and look through the first couple of tutorials.
    As a note, it is best to put all your objects into packages, especially if you use JDK 1.4 or higher.

  • Jsp and JavaBean problem

    Hi All,
    I need UR help
    Problem:
    I have a javaBean and a jsp page say test.class and test.jsp respectively.
    Now the problem is when i run my jsp in web browser with path
    http://localhost:8080/mypackage/test.jsp and use test.class in it. It give me an error Class test.class Not Found but when i give the path http://localhost:8080/examples/jsp/parentpackage/mypackage/test.jsp
    it works fine.
    I am using Tomcat 3.2 and i have already made changes in server.xml for my jsp files thats why i can run my programs with the earlier path but dont know why its giving the error when i use javabean,
    Also i have put my javabean class in---parentpackage/mypackage/test.class
    Thanks
    Amit

    hi there,
    Thanks for you time, here i have placed the source for jsp and javabean
    Please excuse me if you find the code unproper
    Code for JSP:
    <%
    response.setHeader("Pragma","No-cache");
    response.setDateHeader("Expires",0);
    response.setHeader("Cache-control","No-cache");
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Internal Clarification-Agent View</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body background="images/c.jpg" bgproperties="fixed">
    <%@ page language="java" import="java.sql.*" %>
    <%@ page import="javax.servlet.*" %>
    <%@ page import="java.io.*" %>
    <%@ page import="java.util.*" session="true"%>
    <%@ page import="java.util.Date" %>
    <%@ page import="java.sql.Timestamp" %>
    <%@ page import="java.text.*" %>
    <%@ page import="java.lang.*" %>
    <%@ page import="javax.servlet.http.*"%>
    <jsp:useBean id="navi" class="arvato.interclarification.rqchunk" scope="session" />
    <%
    try{
    Connection con = null;
    PreparedStatement ps = null;
    PreparedStatement ps1 = null;
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con = DriverManager.getConnection("jdbc:odbc:interdsn","","");
    String qrno = request.getParameter("qrno");
    String rdb = request.getParameter("rb");
    String key = request.getParameter("key");
    String cname = request.getParameter("cname");
    //out.print(key);
    //if(st.equals("All")){
    String sql="";
    if(rdb!=null){
    if(rdb.equals("1")){
    if(qrno==null||qrno.equals("")){
    sql = "SELECT * FROM crequired ORDER BY adate DESC";
    else if(qrno!=null){
    sql = "SELECT * FROM crequired WHERE queryno LIKE '"+qrno+"%'";
    }else if(rdb.equals("2")){
    if(key==null||key.equals("")){
    sql = "SELECT * FROM crequired ORDER BY adate DESC";
    else if(key!=null){
    sql = "SELECT * FROM crequired WHERE clarification LIKE '"+key+"%'";
    else if(rdb.equals("3")){
    if(cname==null||cname.equals("")){
    sql = "SELECT * FROM crequired ORDER BY adate DESC";
    else if(cname!=null){
    sql = "SELECT * FROM crequired WHERE fname LIKE '"+cname+"%'";
    if(rdb==null)
    sql = "SELECT * FROM crequired ORDER BY adate DESC";
    ps = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    //ps.setString(1,space);
    /*}else{
    sql = "SELECT * FROM crequired WHERE status=? AND space=?";
    ps = con.prepareStatement(sql);
    ps.setString(1,st);
    ps.setString(2,space);
    ResultSet rs = ps.executeQuery();
    %>
    <table width="100%" border="0" cellspacing="0">
    <tr>
    <td width="50%"><strong><img src="images/microsoftlogo1.jpg" width="288" height="94"></strong></td>
    <td width="50%"><div align="right"><strong><img src="images/logo2.jpg" width="177" height="77"></strong></div></td>
    </tr>
    </table><br>
    <hr noshade color="#000000">
    <div align="center"><font color="#990000" size="4" face="Verdana, Arial, Helvetica, sans-serif"><strong>CSR
    VIEW</strong></font>
    </div>
    <form name="form" method="post" action="agentview1.jsp">
    <table width="59%" border="1" align="center" cellpadding="2" cellspacing="0">
    <tr>
    <td width="49%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>
    <input name="rb" type="radio" value="1" <%if(rdb!=null){if(rdb.equals("1")){out.print("checked");}}%>>
    <font size="1">SEARCH BY QUERY NUMBER:</font></strong></font></td>
    <td width="51%"><input name="qrno" type="text" id="qrno"></td>
    </tr>
    <tr>
    <td><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
    <input type="radio" name="rb" value="2" <%if(rdb!=null){if(rdb.equals("2")){out.print("checked");}}%>>
    <font size="1"> SEARCH BY KEY WORD:</font></font></strong></td>
    <td><input name="key" type="text" id="key"></td>
    </tr>
    <tr>
    <td><input type="radio" name="rb" value="3" <%if(rdb!=null){if(rdb.equals("3")){out.print("checked");}}%>>
    <strong><font size="1" face="Verdana, Arial, Helvetica, sans-serif">SEARCH
    BY CSR NAME:</font></strong></td>
    <td><input name="cname" type="text" id="cname"></td>
    </tr>
    <tr>
    <td colspan="2"><div align="center">
    <input type="submit" name="Submit" value="Submit">
    </div></td>
    </tr>
    </table>
    </form><br>
    Back
    <%
    navi.setchunk(10);
    navi.setRS(rs);
    String v="";
    String vv=request.getParameter("off");
    if(vv==null){v="1";}
    else{
    v=vv;
    int i=Integer.parseInt(v);
    navi.setcursor(i);
    ResultSet rs2=navi.getRS();
    int h1=1;
    if(request.getParameter("off")!=null) h1=Integer.parseInt(request.getParameter("off"));
    int h2= navi.getchunk();
    int h3= navi.getcount();
    int offset=(h3-h1)<h2?h3:(h1+h2-1);
    %>
    <table width=100%><tr><td width=33%> </td><td align=center width=34%><font face="verdana, arial" size=2 color=#000000>Displaying <%=h1%> to <%=offset%> of <font size=4><%=h3 %></font></font></td><td width=33%> </td></tr></table>
    <%
    int c1=navi.getcount(),c2=navi.getchunk();
    int c3=navi.getcursor();
    int c4=c3+c2;
    int c5=c3-c2;
    %>
    <table width=100% ><tr><td align=left width=100% >
    <%
    if(c3>c2 && c3<=c1){
    out.print("<a href=\"agentview1.jsp?n=y&off="+c5+"\">Previous</a>");
    %></td><td align=right width=100%>
    <%
    if(c1>c2 && (c1-c3)>=c2){
    out.print("<a href=\"agentview1.jsp?n=y&off="+c4+"\">Next</a>");}
    %>
    </td></tr></table>
    <table width="1359" border="0" cellspacing="1">
    <tr bgcolor="#3C6C84">
    <th width="2%"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">S.No.</font></th>
         <th width="5%"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Query No</font></th>
    <th width="5%"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Clarification
    Posting Date & Time</font></th>
         <th width="3%"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Posted
    By</font></th>
    <th width="6%"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Received
    By</font></th>     
    <th width="3%"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Sub
    Process </font></th>
         <th width="4%"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Region</font></th>
    <th width="5%"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Status</font></th>     
    <th width="15%"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Clarification
    Required OnQuery </font></th>
    <th width="18%"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Solution</font></th>
    <th width="8%"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Date
    & Time Visited On</font></th>
    <th width="7%"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Date
    & Time Closed On</font></th>
    <th width="5%"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Remarks</font></th>
    </tr>
    <%
    int m = 0;
    for(int l=0;l<c2 && i<=c1;l++,i++){
    //while(rs.next()){
    m = m+1;
    String queryno = rs.getString("queryno");
    //out.print(queryno);
    %>
    <tr>
    <td bgcolor="#FFFFCC"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><%=m%></b></font></td>
         <td width="5%" bgcolor="#FFE4CA"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><%=queryno%></b></font></td>
    <td bgcolor="#FFFFCC"><font face="Verdana, Arial, Helvetica, sans-serif" size="1">
    <%Date d1 = rs.getDate("adate");
         String dd1="";
         SimpleDateFormat sddf = new SimpleDateFormat("MM/dd/yyyy");
         dd1 = sddf.format(d1);
         Date t1 = rs.getTime("atime");
         String tt1="";
         SimpleDateFormat stdf = new SimpleDateFormat("HH:mm");
         tt1 = stdf.format(t1);
         String ttm = dd1+" "+tt1;
         out.print(ttm);     
         %></font>
    </td>
         <td bgcolor="#FFE4CA"><font face="Verdana, Arial, Helvetica, sans-serif" size="1">
    <b><%String fnm = rs.getString("fname");
    String lnm = rs.getString("lname");
    String nm = fnm+" "+lnm;
    out.print(nm);
    %></b></font></td>
    <td width="6%" bgcolor="#FFFFCC"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><%
         String tnm = rs.getString("tname");
         if(tnm.equals("null")||tnm.equals("-")){}else{out.print(tnm);}
         %></font></td>
         <td bgcolor="#FFE4CA"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><%=rs.getString("space")%></b></font></td>
         <td bgcolor="#FFFFCC"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><%String rg = rs.getString("region");
         if(rg==null||rg.equals("null")){}else{out.print(rg);}%></b></font></td>
         <%String status = rs.getString("status");
         if(status.equalsIgnoreCase("New")){%><td bgcolor="#FF0000"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#FFFFFF"><b><%=status%></b></font></td>
         <%}else if(status.equalsIgnoreCase("Open")||status.equalsIgnoreCase("Awaiting MS Reply")){%><td bgcolor="#FFCC33"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#FFFFFF"><b><%=status%></b></font></td><%}else{%><td bgcolor="#00CC00"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#FFFFFF"><b><%=status%></b></font></td><%}%>
    <td bgcolor="#FFE4CA"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#0000CC"><%=rs.getString("clarification")%></font></td>
         <%
    //String queryno = rs.getString("queryno");
    String qry1 = "select * from csolution where queryno=?";
    ps1 = con.prepareStatement(qry1);
    ps1.setString(1,queryno);
    ResultSet rs1 = ps1.executeQuery();
    while(rs1.next()){%>
    <td bgcolor="#FFFFCC"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><%=rs1.getString("solution")%></font></td>
         <td bgcolor="#FFE4CA"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><%
         Date dp = rs1.getDate("dateofopen");
         String dp1="";
         SimpleDateFormat spdf = new SimpleDateFormat("MM/dd/yyyy");
         dp1 = spdf.format(dp);
         Date tp = rs1.getTime("timeofopen");
         String tp1="";
         SimpleDateFormat stpf = new SimpleDateFormat("HH:mm");
         tp1 = stpf.format(tp);
         String tpm = dp1+" "+tp1;
         out.print(tpm);
         %></font>
    </td>
         <td width="5%" bgcolor="#FFFFCC"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><%
         Date dc = rs1.getDate("dateofclose");
         String dc1="";
         SimpleDateFormat scdf = new SimpleDateFormat("MM/dd/yyyy");
         dc1 = scdf.format(dc);
         Date tc = rs1.getTime("timeofclose");
         String tc1="";
         SimpleDateFormat stcf = new SimpleDateFormat("HH:mm");
         tc1 = stcf.format(tc);
         String tcm = dc1+" "+tc1;
         out.print(tcm);
         %></font>
    </td>
         <td width="16%" bgcolor="#FFE4CA"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><%String remarks = rs1.getString("remarks");
         if(remarks==null){}else{out.print(remarks);}
         %></font></td>
    <%}navi.setcursor();
    }con.close();}catch(Exception e){out.print(e);}%>
    </tr>
    </table><br>
    <font size="2" face="Verdana, Arial, Helvetica, sans-serif">Back to
    Main Menu</font>
    </body>
    </html>
    Code for javaBean:
    package arvato.interclarification;
    import javax.servlet.http.*;
    import java.sql.*;
    public class rqchunk
              ResultSet rs=null;
              int chunk=5;
              int count=0;
              int cursor=1;
              public rqchunk(){}
              public void setRS(ResultSet rset) throws SQLException
                   rs = rset;
                   int cnt=0;
                   while(rs.next())
                        cnt++;
                   rs.absolute(1);
                   count=cnt;
              public void setcursor()throws SQLException
                   cursor++;
                   rs.absolute(cursor);
              public void setcursor(int i)throws SQLException
                   cursor=i;
                   rs.absolute(cursor);
              public int getcursor()
                   return cursor;
              public int getchunk()
                   return chunk;
              public void setchunk(int i)
                   chunk=i;
              public void setcount(int j)
                   count=j;
              public int getcount()
                   return count;
              public ResultSet getRS()
                   return rs;
              public void clearRS()
                   cursor=0;
                   rs=null;
    Please excuse me if my codes are not understandable enough
    Thanks
    Amit

  • Difference between ActiveX Controls and JavaBeans

    Hi,
    I have just started programming Java Beans. Being from Microsoft background my first feel is that Java Beans are to Java what ActiveX is to Microsoft. Is this true? I hope that some of the gurus out there will be better able to explain.
    Thankx in adavance...

    This is pretty much true. ActiveX and JavaBeans fulfil similar roles, they just do it in completely different ways.
    ActiveX relies on COM, a JavaBean is just another class using specific naming conventions.
    But you now need to forget all about the similarities! Bringing an ActiveX knowledge to JavaBeans will likely get you in trouble. Learn Beans for what they are - Beans.
    The online training page at develope.java.sun.com ha lots of resources for finding your way around.
    Cheers

  • JTables and frequency count report

    Is it possible to use jTable and make the cells un-editable and have it set up where if you click on a cell it could perform a specific action? I�m working on a program that calculates a frequency count report and I want to be able to click on the cell and have it display in another window the observations that contributed to that cells count. Is this possible using jTable or is there a better way to get what I want? Thanks for any suggestions.

    Yes, it looks to me as if it should be possible.

  • Help with jsp and javaBean in eclipse/Tomcat

    Hi,
    I am new to JSP and JavaBean. I am going through tutorial for a jsp page that uses a javaBean. I am using eclipse to create jsp page and the java bean.
    My eclipse project "Date" has five package as under:-
    1. Deployment Descriptor
    2. Java Resources: src
    3. build
    4. WebContent
    I have my data.jsp page in WebContent/WEB-INF/ folder. When I just run date.jsp in a browser as: http://localhost:8080/Date/date.jsp, it gets launched into the browser correctly. But when I add a JavaBean "TimeFormatterBean.java" in the Java Resources:src folder and use it in date.jsp page, I get errors as under:-
    org.apache.jasper.JasperException: Unable to compile class for JSP:
    An error occurred at line: 5 in the jsp file: /date.jsp
    TimeFormatterBean cannot be resolved to a type
    2: pageEncoding="ISO-8859-1"%>
    3: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    4:
    5: <jsp:useBean id="formatter" class="TimeFormatterBean"/>
    6:
    7: <html>
    8: <head>
    The data.jsp page is as under:-
    <jsp:useBean id="formatter" class="TimeFormatterBean"/>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
         <h1> Date JSP </h1>
         <p> The  current time is:
         <%= new java.util.Date() %>
         <jsp:getProperty name="formatter" property="name"/>
         </p>
    </body>
    </html>I can see "TimeFormatterBean.class" in build/classes folder.
    If anyone could please help me out with this, it would be very helpful
    Thanks a lot!

    You probably should place TimeFormatterBean inside a package, or maybe you could try importing it , even if it�s in the default package, with something like this <%@ page import="TimeFormatterBean" %> at the top

  • Jtable and database

    hi,
    i am using jdevlopper 10g and oracle 10g express.
    i create a database and a new connection to it.
    in the first frame, i created a new jtable and i want that it containts data from the database.
    is any one can help me.
    thanks

    Hi,
    you have two options:
    - Use ADF and ADF Swing, in which cae the database connect is through a business service (e.g. ADF Business Components or EJB)
    - Create a JDBC connection to the database and populate the JTable model with the data (which is cumbersome). You find tutorials on the web of how to do this.
    Frank

  • JTable and events

    Hi,
    I am fairly new to Swing. I don't understand the following behaviour of JTables. If I minimize the frame containing the JTable, and afterwards maximize it again, the getValuAt method is called again for all visible rows and columns, even if the table data did not change. The same happens whit a mousemove over the JTable, and if another screen is dragged over the screen and afterwards dragged away from the screen.
    It is possible this is normal, but it affects the performance of the application in a quite considerable way.
    Greetings,
    Marc

    StansislavL is right, when the JTable is repainted also the data needs to be repainted and therefor retrieved form the DataModel. The way to solve your performance issues is to read the data once into a Vector of beans and use this to retrieve the value's for your JTable, like:public Object getValueAt (int row, int col)
      SomeBean sb = (SomeBean) data.get(row) //data = Vector of beans
      switch (col)
        case 0: return sb.getID();
        case 1: return sb.getName();
      return null;
    }greetz,
    Stijn

  • JTable and cell color

    Hello, hope you can help me here -
    I have a JTable, and based on the value of a certain column in a row, I want the background color of that entire row to change to a different color. How can I perform this operation?
    I have tried to override JTable's prepareRenderer, but it doesn't seem to be working.
    Any clues?
    Thanks!
    -Kirk

    Hi.
    First of all. Try searching the forum there have been plenty of posts on this subject.
    Now to answer your question of how to set the color. The trick lies in the cellrenderer.
    A JTabel contains several models internally. If I'm not mistaking the ColumnModel contains the appropriate rendere for every column. The simplest thing to do in my opinion is to use a decorator pattern on the TableCellRenderer interface. Something along the likes of this.
    import java.awt.Color;
    import java.awt.Component;
    import javax.swing.JTable;
    import javax.swing.table.TableCellRenderer;
    public class ColorTableCellRenderer implements TableCellRenderer {
    private TableCellRenderer render;
    public ColorTableCellRenderer( TableCellRenderer render ){
    this.render = render;
    * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object,
    * boolean, boolean, int, int)
    public Component getTableCellRendererComponent( JTable table , Object value , boolean isSelected , boolean hasFocus ,
    int row , int column ) {
    if( table != null ){ //Replace with specific condition
    Component cmp = this.render.getTableCellRendererComponent( table , value , isSelected , hasFocus , row , column );
    cmp.setBackground( Color.cyan );
    //Maybe need to call a validate or setOpaque. if experiencing problems.
    return cmp;
    }else{
    return this.render.getTableCellRendererComponent( table , value , isSelected , hasFocus , row , column );
    After that the easiest to do is set the defaultCellrenderer of your table in the following fashion.
    table.setDefaultRenderer(Object.class, new ColorTableCellRenderer( table.getDefaultRenderer(Object.class) ));
    Or this should also work.
    table.getColumnModel().getColumn(0).setCellRenderer(new ColorTableCellRenderer(chosenRenderer));
    Hope this helps & Good luck!

  • Any CASE tools for Java, JSP, and JavaBeans?

    For Java, JSP, and JavaBeans can we find something that can help us automate certain tasks?
    For example, CASE tools is an acronym for Computer Aided Software Engineering tools. I have a colleague use software to generate robust code for the database layer and with a few clicks of a button after the database is designed he can generate code that would otherwise take an hour or even hours to write and debug and test.
    Thanks for your time and help in advance!
    Cecilia

    The ones I know are MVCase (from Brazil) and Jude (from Japan). Both are free and I haven't fully tested them yet. It may help you.

  • Help with TableRowSorter , JTable and JList

    Hello,
    I�m developing an application in which I�m using a Jtable and Jlist to display data from a database. Jtable and Jlist share the same model.
    public class DBSharedModel extends DefaultListModel implements TableModelFor the Jtable I set a sorter and an filter
    DBSharedModel dataModel = new DBSharedModel();
    Jtable jTable = new JTable(dataModel) ;
    jTable.createDefaultColumnsFromModel();
    jTable.setRowSelectionAllowed(true);
    TableRowSorter<DBSharedModel> sorter = new TableRowSorter <DBSharedModel> (dataModel);
    jTable.setRowSorter(sorter);From what I read until now JavaSE 6 has NOT a sorter for JList (like one for JTable).
    So, I am using one from a this article http://java.sun.com/developer/technicalArticles/J2SE/Desktop/sorted_jlist/index.html
    When I sort the data from the table, I need to sort the data from the list, too.
    My ideea is to make the Jlist an Observer for the Jtable.
    My questions are:
    1.     How can I find if the sorter makes an ASCENDING or DESCENDING ordering?
    2.     How can I find what the column that is ordered?
    Or if you have any idea on how can I do the ordering on Jlist to be simultaneous to Jtable .
    Please help!
    Thank you

    Oh what the hell:
    Sun's basic Java tutorial
    Sun's New To Java Center. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
    http://javaalmanac.com. A couple dozen code examples that supplement The Java Developers Almanac.
    jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
    JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
    Bruce Eckel's Thinking in Java (Available online.)
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java. This one has been getting a lot of very positive comments lately.

  • JScrollPanel, JTable, and a HorizontalScrollBars

    Am creating a JScrollPane, a JTable, and adding the table to the pane.
    I am also creating MyTableMode which extends AbstractTabelModel. MyTableModel provides the interface between the JTable and my particular data. I am able to display and edit the data, that interface is working fine.
    When I have more than about 10 rows of data, the vertical scroll bars appear. This is what I expect.
    But if there are more columns than can be seen in the viewport, the horizontal scroll bars do not appear. This is not what I expect.
    Example: if I create table with 72 rows by 72 columns, only rows 1-10 and columns 1-40 are visible (based on dialog size, preferred size, etc.). The vertical scroll bars are present, but the horizontal scroll bars are not. The user will not be able to scroll the viewport and see columns 41-72.
    I've read (and re-read) the "How to use Tables" and "How to use Scrollpanes", tutorials, and do not see anything obvious. Probably missed something. I did notice that none of the table examples have horizontal scrioll bars.
    Any suggestions?

    It's one of those days. Here is code with the imports:
    package components;
    * TableDemo.java requires no other files.
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.AbstractTableModel;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    * TableDemo is just like SimpleTableDemo, except that it
    * uses a custom TableModel.
    public class TableDemo extends JPanel {
        private boolean DEBUG = false;
        public TableDemo() {
            super(new GridLayout(1,0));
            JTable table = new JTable(new MyTableModel());
            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 MyTableModel extends AbstractTableModel {
            public int getColumnCount() {
                //return columnNames.length;
                return 72;
            public int getRowCount() {
                //return data.length;
                return 72;
            public String getColumnName(int col) {
                //return columnNames[col];
                return Integer.toString(col);
            public Object getValueAt(int row, int col) {
                //return data[row][col];
                return 0;
            public boolean isCellEditable(int row, int col) {
                return false;
         * 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();
    }

  • Simplify JTable with JavaBeans

    Here's the problem. It seems like I write the same code over and over when I work with JTables. I have a set of objects that I want to display in a JTable where the columns are their instance members or some subset of them. JTable is very flexible and cool, but it's sooo cumbersome to work with causually. Can JavaBeans simplify this?
    I've written some reusable parts that have reduced my overhead in writing a GUI code. I used to write a TableModel, a ColumnModel, another Sorting TableModel, and a JTable. Now all I have to do is write a single ColumnModel that knows about what fields that I want to display out of an object. But, I was wondering if JTable already had something like this if your object was a JavaBean. I looked in java.bean package, and found some classes that could be used like my special ColumnModel, but I couldn't find anything in JTable or other parts of Swing that would work in displaying JavaBeans. Any ideas?
    thanks
    charlie
    ps I saw the post on MITable. Looks cool, but I don't think it's free.

    As soon as I'll have found some sponsor it would be free software.

Maybe you are looking for

  • Regarding XMLStreamWriter2

    Dear all, I am in a process of converting an XML file to java using XMLStreamWriter2 class and i am successfull in doing that . But i am stucked when this problem came i have an XML line as <value>80</value> i dont know how to set the value For eg, <

  • Image Button in BO DS

    Hi , I wish to add an image to my application. But as per the tutorials, i get an option to load file. But I am using version1.1, I dont see the option. May be something I am lacking out, Kindly help. BR Adlin

  • User State Migration Relocation Pattern

    I am using USMT 4.0 to capture data from a Windows XP SP3 system with an additional D: (DATA) drive. I can accomplish this using the generatedrivepatterns option or specifying a file pattern of "D:\* [*]". In my local, uncompressed store I can see th

  • I want to downgrade iOS 7.1.1 to 6.1.2 on iPhone 4 (A1332B). How do I do that? Can this be done in official service center?

    I want to downgrade iOS 7.1.1 to 6.1.2 on iPhone 4 (A1332B). How do I do that? Can this be done in official service center? Why I can't do it through iTunes?

  • File to 2 Communication Channels on same Business Service / PI 7.0

    Hi all, I got a new question. I want to place a file in two different directories on the same Business Service. Think I have to use 2 CC for that. Background: We receive a file and want to forward that to a directory (e.g. "/in"). So far so good. But