How to write an element in a  JTable Cell

Probably it's a stupid question but I have this problem:
I have a the necessity to build a JTable in which, when I edit a cell and I push a keyboard button, a new Frame opens to edit the content of the cell.
But the problem is how to write something in the JTable cell, before setting its model. Because, I know, setCellAT() method of JTree inserts the value in the model and not in the table view. And repainting doesn't function!
What to do??
Thanks

Hi there
Depending on your table model you should normally change the "cell value" of the tablemodel.
This could look like:
JTable table = new JTable();
TableModel model = table.getModel();
int rowIndex = 0, columnIndex = 0;
model.setValueAt("This is a test", rowIndex, columnIndex);
The tablemodel should then fire an event to the view (i.e. JTable) and the table should be updated.
Hope this helps you

Similar Messages

  • How to blink the text with in JTable Cell?

    Hi Friends,
    I am relatively new to Java Swings. I have got a requirement to blink the text with in the JTable cell conditionally. Please help with suggestions or sample codes if any.
    Thanks in Advance.
    Satya.

    I believe Swing components support HTML tags.
    So you might be able to wrap your text in <BLINK>I am blinking !</BLINK>
    tags.
    If that doesn't work, you probably have to create your own cell renderer, and force a component repaint every second or so... messy.
    regards,
    Owen

  • How to write each element of a set to the excel sheet?

    I am trying to iterate through each element of the set and write each of them to an excel file? Can Somebody help me to achieve this?
    Code snippet is:
    Iterator<String> nameIterator = names.iterator();
        for(int size = 0;size<names.size();size++){       
      row = mdm_lastLoginDate.createRow(size);
      //cell = row.createCell(1);
      while(nameIterator.hasNext()){
      String setName = nameIterator.next();
      cell = row.createCell(1);
      cell.setCellValue(setName);
      System.out.println("setName:->"+setName);
      mdm_lastLoginDate.autoSizeColumn(size);
    above code prints each element in the console but not getting each value in the excel file. I am only getting the last value.
    Thanks & regards
    Amita

    As already communicated several times to you - please use the correct space for your posts.
    I'll move this thread again to Master Data Management (SAP MDM), however - and for the last time - please get familiar with The SCN Rules of Engagement and note that your account will be disabled if you repeatedly fail to follow them.
    --Vlado (SCN Moderator)

  • How to write set Element in Java

    Is there a way to write the following in java so I can do it in a method?
    <set property="inputValue" value="${bindings.SubCommandId.inputValue}" target="${data.ServiceEventEditUIModel.SubCommandId}"/>

    I solved it:
    JUCtrlValueBinding sub = (JUCtrlValueBinding)ctx.getBindingContainer().findCtrlBinding("subCommandId1");
    sub.setInputValue(null);

  • How to write text vertically in an table cell?

    Is it possible to make a table cell where the
    text would be written along a vertical base line?
    I found how to make a text box and rotate it
    vertically.
    How may I place such a text box in a table cell?
    dan    

    Hello daniel,
    if the table will not be resized or repositioned a lot, the best way to display what you want to have is to create a textbox with the styles and adjustments you need, rotate it and place it over the table cell. Be sure to make the cell big enough to pretend the text of the textbox would be inside of it. The textbox has to be a fix positioned object in the top layer.
    It's only a work-around, but the best you can achieve.
    Frank.

  • How to write elements line bye line in xml?

    Hi Everyone,
    Can anyone of u tell me how to write the elements line by line into xml ?
    <username>thilothama</username> <password>pwd1</password><username>Talam</username>
    into      <username>thilothama</username>
         <password>pwd1</password>
         <username>test</username>
    thanks
    thilothama

    How do you print it today? Without knowing that, the answer is probably "add a \n in the right place"...

  • How to include a jButton in the jTable CellEditor?

    sir,
    how can include a jButton in the jTable cell Editor as we include checkbox & Combo inthe Cell Editor?
    thks.

    There is c:import tag in the JSTL that will include the HTML from a file on another server.

  • How to display cusomized custom tooltip(jwindow)  in jtable cell position

    Hi,
    i am trying to display custom tooltip for jtable cell. i created custom tooltip(jwindow) and on mouseover of jtable cell i am trying to display the custom tooltip.
    But it is not display the position of jtable cell. How to display the exact position of jtable cell
    please help me on this.

    Did you read the posting directly below yours which was also about a custom tool tip?
    JScrollableToolTip is buggy
    The code presented there shows the tool tip in the proper location.
    For more help create a [url http://sscce.org]SSCCE, that demonstrates the incorrect behaviour.
    Don't forget to read the "Welcome to the new home" posting at the start of the forum to learn how to use the "code tags" so posted code is formatted and readable.

  • Centering text in JTable cells

    How do I center the text in JTable cells? By default, all data is left aligned.
    Thanks,
    Jason

    Read up on cell renderers from the Swing tutorial on "Using Tables":
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editrender
    Here's an example to get you started.
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.text.*;
    public class TableRenderer extends JFrame
        public TableRenderer()
            String[] columnNames = {"Date", "String", "Integer", "Decimal", "Boolean"};
            Object[][] data =
                {new Date(), "A", new Integer(1), new Double(5.1), new Boolean(true)},
                {new Date(), "B", new Integer(2), new Double(6.2), new Boolean(false)},
                {new Date(), "C", new Integer(3), new Double(7.3), new Boolean(true)},
                {new Date(), "D", new Integer(4), new Double(8.4), new Boolean(false)}
            DefaultTableModel model = new DefaultTableModel(data, columnNames);
            JTable table = new JTable( model )
                //  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 scrollPane = new JScrollPane( table );
            getContentPane().add( scrollPane );
            //  Create cell renderer
            TableCellRenderer centerRenderer = new CenterRenderer();
            //  Use renderer on a specific column
            TableColumn column = table.getColumnModel().getColumn(3);
            column.setCellRenderer( centerRenderer );
            //  Use renderer on a specific Class
            table.setDefaultRenderer(String.class, centerRenderer);
        public static void main(String[] args)
            TableRenderer frame = new TableRenderer();
            frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
            frame.pack();
            frame.setVisible(true);
        **  Center the text
        class CenterRenderer extends DefaultTableCellRenderer
            public CenterRenderer()
                setHorizontalAlignment( CENTER );
            public Component getTableCellRendererComponent(
                JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                return this;

  • How to write Header and Footer elements in Write file Adapter

    Hi,
    I have a requirement to write the file.The write file contains header and footer elements ,how we can write these elements. These elements are fixed for all files.these are not come from any input.below is the sample file.
    $begintable
    name,Id,Desg
    ad,12,it
    $endtable

    Hi,
    I have created the XSD for you, and i created a sample SOA Composite which writes the file same like what you want, the below XSD can write a file with one header record, multiple data records and one trailer record.
    <?xml version="1.0" encoding="UTF-8" ?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd"
    xmlns:tns="http://TargetNamespace.com/WriteFile"
    targetNamespace="http://TargetNamespace.com/WriteFile"
    elementFormDefault="qualified" attributeFormDefault="unqualified"
    nxsd:version="NXSD" nxsd:stream="chars" nxsd:encoding="UTF-8">
    <xsd:element name="Root-Element">
    <xsd:complexType>
    <!--xsd:choice minOccurs="1" maxOccurs="unbounded" nxsd:choiceCondition="terminated" nxsd:terminatedBy=","-->
    <xsd:sequence>
    <xsd:element name="RECORD1">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="header" type="xsd:string"
    nxsd:style="terminated" nxsd:terminatedBy="${eol}"
    nxsd:quotedBy='"'/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="RECORD2" minOccurs="1" maxOccurs="unbounded">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="data1" type="xsd:string"
    nxsd:style="terminated" nxsd:terminatedBy=","
    nxsd:quotedBy='"'/>
    <xsd:element name="data2" type="xsd:string"
    nxsd:style="terminated" nxsd:terminatedBy=","
    nxsd:quotedBy='"'/>
    <xsd:element name="data3" type="xsd:string"
    nxsd:style="terminated" nxsd:terminatedBy="${eol}"
    nxsd:quotedBy='"'/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="RECORD4" nxsd:conditionValue="$endtable">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="trailer" type="xsd:string"
    nxsd:style="terminated" nxsd:terminatedBy="${eol}"
    nxsd:quotedBy='"'/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>
    Hope this helps,
    N

  • How to write a composite element in iterator?

    Hi,
      I want to write a composite element in iterator which has the same result as BSP element like this in BSP layout:
      <htmlb:link id = "link1"
                  reference = "http://www.sap.com">
      <htmlb:textView id = "text1"
                      textColor = "<%=gv_color%>"
                      text      = "ddddd" />
      </htmlb:link>
      Do you know how to write this in iterator? Thanks!

    Hi,
    you can use the replacement bee:
    data: o_link TYPE REF TO cl_htmlb_link.
    CASE p_column_key.
        WHEN 'column_name'.
            w_event = model->get_sapevent_string(
                            name    = 'activity'
                            system  = 'crm'
                            key     = o_ref->guid ).
            o_link    = cl_htmlb_link=>factory( id  = p_cell_id
                                              text = 'text'
                                              tooltip = 'tooltip'
                                              reference = w_event ).
            p_replacement_bee  = o_link.
    ENDCASE.
    in w_event you declare your event, eg. the calling of a
    sap event or you navigation.
    you can find an example in:
    <a href="/people/thomas.jung3/blog/2004/09/15/bsp-150-a-developer146s-journal-part-xi--table-view-iterators by Thomas Jung</a>
    grtz
    Koen

  • How to write the JTables Content into the CSV File.

    Hi Friends
    I managed to write the Database records into the CSV Files. Now i would like to add the JTables contend into the CSV Files.
    I just add the Code which Used to write the Database records into the CSV Files.
    void exportApi()throws Exception
              try
                   PrintWriter writing= new PrintWriter(new FileWriter("Report.csv"));
                   System.out.println("Connected");
                   stexport=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                   rsexport=stexport.executeQuery("Select * from IssuedBook ");
                   ResultSetMetaData md = rsexport.getMetaData();
                   int columns = md.getColumnCount();
                   String fieldNames[]={"No","Name","Author","Date","Id","Issued","Return"};
                   //write fields names
                   String rec = "";
                   for (int i=0; i < fieldNames.length; i++)
                        rec +='\"'+fieldNames[i]+'\"';
                        rec+=",";
                   if (rec.endsWith(",")) rec=rec.substring(0, (rec.length()-1));
                   writing.println(rec);
                   //write values from result set to file
                    rsexport.beforeFirst();
                   while(rsexport.next())
                        rec = "";
                         for (int i=1; i < (columns+1); i++)
                             try
                                    rec +="\""+rsexport.getString(i)+"\",";
                                    rec +="\""+rsexport.getInt(i)+"\",";
                             catch(SQLException sqle)
                                  // I would add this System.out.println("Exception in retrieval in for loop:\n"+sqle);
                         if (rec.endsWith(",")) rec=rec.substring(0,(rec.length()-1));
                        writing.println(rec);
                   writing.close();
         }With this Same code how to Write the JTable content into the CSV Files.
    Please tell me how to implement this.
    Thank you for your Service
    Jofin

    Hi Friends
    I just modified my code and tried according to your suggestion. But here it does not print the records inside CSV File. But when i use ResultSet it prints the Records inside the CSV. Now i want to Display only the JTable content.
    I am posting my code here. Please run this code and find the Report.csv file in your current Directory. and please help me to come out of this Problem.
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.table.*;
    public class Exporting extends JDialog implements ActionListener
         private JRadioButton rby,rbn,rbr,rbnore,rbnorest;
         private ButtonGroup bg;
         private JPanel exportpanel;
         private JButton btnExpots;
         FileReader reading=null;
         FileWriter writing=null;
         JTable table;
         JScrollPane scroll;
         public Exporting()throws Exception
              setSize(550,450);
              setTitle("Export Results");
              this.setLocation(100,100);
              String Heading[]={"BOOK ID","NAME","AUTHOR","PRICE"};
              String records[][]={{"B0201","JAVA PROGRAMING","JAMES","1234.00"},
                               {"B0202","SERVLET PROGRAMING","GOSLIN","1425.00"},
                               {"B0203","PHP DEVELOPMENT","SUNITHA","123"},
                               {"B0204","PRIAM","SELVI","1354"},
                               {"B0205","JAVA PROGRAMING","JAMES","1234.00"},
                               {"B0206","SERVLET PROGRAMING","GOSLIN","1425.00"},
                               {"B0207","PHP DEVELOPMENT","SUNITHA","123"},
                               {"B0208","PRIAM","SELVI","1354"}};
              btnExpots= new JButton("Export");
              btnExpots.addActionListener(this);
              btnExpots.setBounds(140,200,60,25);
              table = new JTable();
              scroll=new JScrollPane(table);
              ((DefaultTableModel)table.getModel()).setDataVector(records,Heading);
              System.out.println(table.getModel());
              exportpanel= new JPanel();
              exportpanel.add(btnExpots,BorderLayout.SOUTH);
              exportpanel.add(scroll);
              getContentPane().add(exportpanel);
              setVisible(true);
          public void actionPerformed(ActionEvent ae)
              Object obj=ae.getSource();
              try {
              PrintWriter writing= new PrintWriter(new FileWriter("Report.csv"));
              if(obj==btnExpots)
                   for(int row=0;row<table.getRowCount();++row)
                             for(int col=0;col<table.getColumnCount();++col)
                                  Object ob=table.getValueAt(row,col);
                                  //exportApi(ob);
                                  System.out.println(ob);
                                  System.out.println("Connected");
                                  String fieldNames[]={"BOOK ID","NAME","AUTHOR","PRICE"};
                                  String rec = "";
                                  for (int i=0; i <fieldNames.length; i++)
                                       rec +='\"'+fieldNames[i]+'\"';
                                       rec+=",";
                                  if (rec.endsWith(",")) rec=rec.substring(0, (rec.length()-1));
                                  writing.println(rec);
                                  //write values from result set to file
                                   rec +="\""+ob+"\",";     
                                   if (rec.endsWith(",")) rec=rec.substring(0,(rec.length()-1));
                                   writing.println(rec);
                                   writing.close();
         catch(Exception ex)
              ex.printStackTrace();
         public static void main(String arg[]) throws Exception
              Exporting ex= new Exporting();
    }Could anyone Please modify my code and help me out.
    Thank you for your service
    Cheers
    Jofin

  • I am new in indesign scripting, please tell me how to write a script to get  content of a element in xml and then sort all the content

    I am new in indesign scripting, please tell me how to write a script to get  content of a element in xml and then sort all the content

    Hi,
    May the below code is useful for you, but I dont know how to sort.
    Edit the tag as per your job request.
    alert(app.activeDocument.xmlElements[0].contents)
    //Second alert
    var xe = app.activeDocument.xmlElements[0].evaluateXPathExpression("//marginalnote");
    alert(xe.length)
    for(i=0; i<xe.length; i++)
        alert(xe[i].texts[0].contents)
    Regards
    Siraj

  • How to write contents of  an ArrayList to JTable

    I have an ArrayList named 'innercell'. It contains the following contents
    cs123, 0.34567
    cs234, 0.5673
    cs234,cs456, 0.5674
    this arraylist is added to another arraylist 'cells'
    cells.add(innercell);
    now the contents of the 'cells' arraylist is
    cs123, 0.34567
    cs234, 0.5673
    cs234,cs456, 0.5674
    i have created a JTable and its variable name is 'jtable' (object) (*i'm using NetBeans IDE 6.0*)
    and the model of this JTable is as below (it is the generated code by NetBeans IDE 6.0)
    jtable.setModel(new javax.swing.table.DefaultTableModel(
    new Object [][] {
    {null, null},
    {null, null},
    {null, null},
    {null, null},
    {null, null},
    {null, null},
    {null, null},
    {null, null},
    {null, null}
    new String [] {
    "Title 1", "Title 2"
    Class[] types = new Class [] {
    java.lang.String.class, java.lang.String.class
    public Class getColumnClass(int columnIndex) {
    return types [columnIndex];
    i have only 2 columns in the table, and 9 rows
    now i want 2 place contents of 'cells' arraylist to JTable as below
    Tittle 1 Title 2
    cs123 0.34567
    cs234 0.5673
    cs234,cs456 0.5674
    to write in this form i'm using following code
    String[] columnNames={"Title 1","Title 2"};
    Object[][] rowdata=new Object[9][2];
    str=items;//items is the string value.the possible 'items' values {cs123,...}
    sup=value;//value is the double value. the possible 'value' are {0.5674,......}.i'm not given how i'm geting these values
    for(int k=0;k<2;k++){
    if(k==0)
    rowdata[i][k]=str;
    else
    rowdata[i][k]=sup;
    jtable=new JTable(rowdata,columnNames);//is this statement is right to add the contents of arraylist to the table?
    jtable.setVisible(true);
    but it is not working....i'm getting "NullPointerException"

    Swing related questions should be posted in the Swing forum.
    Don't forget to use the [Code Formatting Tags|http://forum.java.sun.com/help.jspa?sec=formatting], so the posted code retains its original formatting.
    Don't use an IDE to generate your code. Learn how to write your own code. Its hard enough to learn how to use Java without learning how to use the IDE as well.
    Use the DefaultTableModel. You can build the model using Vectors or Arrays or by adding individuals rows of data to the model. There is no need to create a custom TableModel.

  • How to write the expression when create the calculated column?

    Dear,
           I want to create some calculated column in my attribute view, but I don't know how to write the code in the expression, is there any introduction about this part, how to use those function and how about the grammar in this expression code ?  or is there any example about this calculated column?
       Thanks for your sincerely answer.

    Hi Zongjie,
    you can find some information about the creation of calculated columns in the HANA Modeling Guide (http://help.sap.com/hana/SAP_HANA_Modeling_Guide_for_SAP_HANA_Studio_en.pdf).
    Within chapter 6.2.1 (Create Analytic Views) you can see under point 7 some basics and also a simple example. The same is also valid for Calculation Views.
    Chapter 8.9 (Using Functions in Expressions) describes the different available functions.
    You also can use the integrated search in the HANA Studio by clicking the "?" button in the button left corner. Then you get some links in the side panel with related information.
    In general you can write your expression manually or you can just drag and drop the functions, elements, operators into the editor window. For example if you drag and drop the "if" function into the editor window you get "if(intarg,arg2,arg3)" inserted. The arguments can be replaced manually or also by drag and drop.
    It is also worse to use the "Validate Syntax" button on top of the editor window. It gives you directly a feedback if your expression syntax is correct. If not you get some helpful information about the problem (ok, sometimes it is a little bit confusing because of the cryptic error message format ).
    Best Regards,
    Florian

Maybe you are looking for

  • Import schema to a different tablespace

    hi, I've exported my instance: EXP SYSTEM/MANAGER@OLDINSTANCE FULL=Y FILE=C:\EXP_FILE.DMP LOG=C:\ERROR_EXP.LOG after I've created new tablespace and new user: CREATE TABLESPACE MAX DATAFILE 'c:\MAX01.dbf' SIZE 3800M REUSE DEFAULT STORAGE (INITIAL 102

  • Can I use the Bluetooth on my Centro to get on the internet.

    I have a refurbished palm Centro (so I wouldn't have to pay an extra $720 for the AT&T unlimited PDA data plan with the phone). It is replacing my old & dying Palm TX. One thing I loved about the TX was the wifi access. It was great to connect to my

  • HELP restoring library & playlist - Itunes 7.7

    Before replacing main HD I copied to external with diskwarrior. Now I want to get back my music & playlists to Main Hard drive. Went to apple store and genius said to do as follows: 1- Open Itunes in Main Hard Drive and select all and remove all song

  • Query: The number of connections possible on APEX

    Hi all, Hope you all are doing good. there is one query, Does the number of connections to apex depends on database memory ??? Is there any limitation on number of connections at the same time ? i have one application, APEX 4.1 DB 11.2.0.2 when it wa

  • Error VC(Visual Composer)

    Dear Experts. I am working with SAP NW 7.4 However with execute the following link for migrate customer development(file PAR), the system genera a dump(Log portal) http://hostname:port/irj/servlet/prt/portal/prtroot/com.sap.portal.runtime.system.cons