Multiple data in each cell in JTable

Hi,
I'm currently working on a program where I need to a JTable that can contain multiple data in each cell. I,ve solved this problem so far by making each cell contain a JList to hold the data, but I'm a little concerned about performance issues. Lets say I have a table with 10x10 cells, that would make 100 JList to render! So my question is if there is a better more light weight way of having multiple data in a JTable cell?
a screendump of the layout can be seen here
/Peter

In the future, Swing related questions should be posted in the Swing forum.
First of all it looks like you have a working program, so are you experiencing any renderering problems?
The only suggesion I would make is to store the ListModel in the table not the JList. I don't think this will improve the renderering, but it should save on resources as you don't need to create multiple JLists.
Or maybe you use JLabels on a panel with a GridLayout.
Or, if you data isn't dynamic, then maybe you create and store an image of each cell and then just use the default renderer.

Similar Messages

  • How can I get right data in a cell of JTable when table  enter editing

    how can I get right data in a cell of JTable when table enter editing

    how can I get right data in a cell of JTable when table enter editing

  • What component is placed default in each cell of JTable?

    Hi,
    What component is placed default in each cell of JTable?

    It depends on the content, see How to Use Tables - Concepts: Editors and Renderers for details.

  • I wish to list consectutive dates in a column.  How do I do this without having to enter each date in each cell?

    I wish to list consectutive dates in a column.  How do I do this without having to enter each date in each cell?

    Hi pdh,
    Enter the first date. I typed 23 feb. Numbers adds the year (if you want a different year, type that as well).
    Press return (enter)
    Click on the first cell.
    You will see a small white crcle at the bottom right of that cell.
    Drag the circle down.
    Regards,
    Ian.

  • BPS Web Interface don't show multiple documents for each cell

    Hi gurus,
    I have an issue... we are trying use text documents from BPS on the WEB interface. Everything works fine, I can input text documents on each cell on the web, and from Query as well.
    I saved several other documents from the query for the very same cell, and I can see these other documents from BPS itself or from the Query by clicking on the title... but on BPS WEB interface, it shows only the last text document saved.
    Is there anything wrong on the configuration, or is it possible for the WEB interface to show the titles so that the user can choose which document he wants to open?
    Thanks in advance,
    Chen

    Hi Luke,
    did you check whether the document attributes are generated for your Characteristics?
    AWB -> Documents -> Administration -> Generated Properties
    There is also a SAP Note 431126, which you might want to consult.
    Regards,
    Eric

  • Multiple dates in row in webi crosstab report

    Hi,
    I am having a PKG_ST_DTM named object of DateTime datatype in database, which contains Timestamp along with it ( we cant change the Database), as we doesnt require the timestamp in our reports, So in IDT we have changed it to  Date without Timestamp by: "convert(varchar(11),PKG_ST_DTM,105) as PKG_ST_DTM" and when I am creating a cross tab report in Webi (4.0)   the dates are Repeating on the Horizontal axis, Below link shows the image/attachment
    http://aryanneil.imgur.com/all/
    I tried with "Avoid Duplicate Row Aggregation" and also in Edit Query " Retrieve Duplicate Rows". But unable to solve
    I need only One date for each cell in the horizontal axis. Please do the needful.
    Thanks in Advance

    Neil,
    It seems issue with date formatting property @ each level-
    @ DB           -     YYYY-MM-DD HH:MI:SS..     --> 2014-05-06 19:00:03:000
    @ IDT           -     DD-MMM-YYYY HH:MI:SS..   --> 06-May-2014 19:03:000
    @ REPORT     -      DD/MM/YY                                         --> 5/6/140
    So you can check these properties at respective levels and do the necessary changes as per requirement
    - M

  • I need to back up and sync multiple iPhones to a single iMac.  Each iPhone has a separate Apple ID and the data from each iPhone needs to be backed up separately from the others.  How can I do this without getting all of the contacts, etc. mixed? Tnx

    I need to back up and sync multiple iPhones to a single iMac.  Each iPhone has a separate Apple ID and the data from each iPhone needs to be backed up separately from the others.  How can I do this without getting all of the contacts, etc. mixed? Tnx

    This might help: http://support.apple.com/kb/HT1495.

  • How to find out each Cell having Data or Not in Excel File by Using WDJ

    Hi Friends,
    I have one doubt on WDJ.
    I have to Upload Excel File. Click on Upload Button in Excel file Data will move to One Bapi. This is I was done. But my Requirement is if any empty Cell in Excel That File not uploaded it display one error message Please upload Correct Excel File
    How to find out each Cell having Data or Not in Excel File by Using WDJ. Please tell me.
    By Using this Code I have Upload Excel File
    InputStream text = null;
         int temp = 0;
         //wdComponentAPI.getMessageManager().reportSuccess("filePath Vijay:::");
         try
                   File file = new File(wdContext.currentContextElement().getResource().getResourceName().toString());     
    FileOutputStream op = new FileOutputStream(file);
                   if (wdContext.currentContextElement().getResource()!= null)
                          text = wdContext.currentContextElement().getResource().read(false);
                             while((temp=text.read())!= -1)
                                  op.write(temp);
                                  op.flush();
                                  op.close();
                                  path = file.getAbsolutePath();
                                  //wdComponentAPI.getMessageManager().reportSuccess("Path Name :::::"+path);
         catch(Exception ex)               
                   ex.printStackTrace();
    But my Requirement is If excel having any Empty Cell that excel file not uploaded.How to do this...
    Regards
    Vijay Kalluri

    Hi my friend
    I would like to share you some APACHE APi´s that i use when i have to read excel files in Web Dynpro.
    JAR = poi-3.2-FINAL-20081019.jar
    Some Example:
    POIFSFileSystem fs;
    HSSFWorkbook wb;
    HSSFSheet sheet;
    String myMexican_ValueFromExcelis = "";
    try {
             fs = new POIFSFileSystem(new FileInputStream();
             // and select the cell "y"
            cell = row.getCell( 0 );
            myMexican_ValueFromExcelis = cell.getCellValue();  
    }cach(Exception e){
    REgargds

  • JTable custom cell renderer for each cell

    Hi,
    Iam trying to implement a JTable in which each cell in a column can be of a different type. i.e it can be a tree node or plain text. Can someone point me to examples where this has been done.
    Iam trying to override getColumnClass but it only takes a column no as parameter. I would like to return a different type depending on the row for which getColumnClass is called. It would help if getColumnClass could take 2 params (row and column). Can someone help.
    Cheers,
    vidyut

    You can override getCellRenderer(int row, int column) of JTable

  • Setting different Tabel Cell SemanticColor for Multiple Columns of each row

    Hi,
    I have requirement of setting different colors to different columns for each row based on some condition in table data.
    The data to table is coming from model, hence table is mapped to model node and attributes.
    I have created Seperate Node CellColorNode with attribue CellClr1 and CellClr2 of type TextView Semantic Color.
    Set the calculated, read only attribute to True. Mapped table columns text view to the CellColorNode->CellClr1 and CellColorNode-->CellClr2 correspondingly.
    Now, my query is how do i set the colors to CellClr1 and CellClr2 attributes. As I need to set the color for multiple columns of each table row.
    Is it in method getColorCellCellClr generated? Any  Example Code?

    Its resolved by following below link
    http://scn.sap.com/thread/158286

  • Dragging only a portion of data from a cell?

    I'm working on a scheduling program (using Java/Swing) that simply has several tables that I drag and drop information pulled from a database. In one table I have it set up so that the user can drag multiple data (people�s names) into a single cell (just concatenate the new name with the existing names). However, I now need the ability to drag a specific name outside the table (to delete it). Since I treat the contents of the whole cell as one big string, I'm stumped as what to do next. I'm new to Java, but have been reading about custom renderers and was wondering if it would be possible to write one that would work in my situation. I'm also open to any other ways that would make specific selection possible. So far this is what has been suggested:
    - find a method of detecting which name is underneath the mouse when a cell is clicked on. You'd need a custom table model such that every cell returns some collection of custom objects representing each name.
    - write a cell renderer so that you can highlight specific names in a cell when the mouse is clicked on one
    - add your drag and drop code using the above two features
    Any help would be greatly appreciated.

    I'm working on a scheduling program (using
    Java/Swing) that simply has several tables that I
    drag and drop information pulled from a database. In
    one table I have it set up so that the user can drag
    multiple data (people�s names) into a single cell
    (just concatenate the new name with the existing
    names). However, I now need the ability to drag a
    specific name outside the table (to delete it). Since
    I treat the contents of the whole cell as one big
    string, I'm stumped as what to do next. I'm new to
    Java, but have been reading about custom renderers
    and was wondering if it would be possible to write
    one that would work in my situation. I'm also open to
    any other ways that would make specific selection
    possible. So far this is what has been suggested:
    - find a method of detecting which name is underneath
    the mouse when a cell is clicked on. You'd need a
    custom table model such that every cell returns some
    collection of custom objects representing each name.
    - write a cell renderer so that you can highlight
    specific names in a cell when the mouse is clicked on
    one
    - add your drag and drop code using the above two
    features
    Any help would be greatly appreciated.I made a cell renderer that is a JPanel subclass that stores JLabels (each representing a name) and the labels will be laid out using a FlowLayout in the panel - that way the names "wrap" in the table cell. Now I need to create a method in my JPanel subclass to return which component is at (x,y), and highlight that component in my renderer getCellRenderComponent() method.
    Any ideas how to implement this method?

  • JLabel as cell of JTable

    Hi All,
    I am using JLabel as a cell of a JTable by overriding getTableCellRendererComponent method of the renderer.But I am not able to select/focus on any of the cell by clicking at cells.However If I use any other componenet like JTextArea, I can select any cell I want.
    I have to use JLabel because i want to put multiple color and fonts in a single cell.I dont't want to use JTextPane because it takes more memory as well as It has wraping problem
    Any help would be greatly appreciated

    It's not a good idea to create a NEW Component each and every time getXXXCellRenderer() is called. Object creation is VERY expensive!!!
    Remember, this Component is merely renderered (e.g. painted, or "rubber-stamped") into the Graphics Context of the JTable, after appropriate sizing to fit the cell, of course. So the SAME component can be used to render each and every cell, each and every time each cell needs to be rendered. (Unless different Component classes are used to render different cells, but still, one of each of these Components should be created in the Constructor, not each time a cell is rendered.)
    I have reworked your code to make it much more efficient, and to make it more readable:
    public class MyTableCellRenderer
        implements TableCellRenderer
        JLabel label = new JLabel();
        public MyTableCellRenderer()
            super();
            this.label.setOpaque(true);
        public Component getTableCellRendererComponent( JTable  table,
                                                        Object  value,
                                                        boolean isSelected,
                                                        boolean hasFocus,
                                                        int     row,
                                                        int     column )
            String st=null;
            st="<HTML><B><FONT Color=Red>" + value.toString() 
               + "</FONT></B></HTML>";
            this.label.setText(st);
            if (isSelected) {
                this.label.setBackground( table.getSelectionBackground());
            } else {
                this.label.setBackground(Color.yellow);
            return this.label;
    }You may find that using HTML as the text of JLabel is much too expensive, especially with a large table. I tried it once, with a table of only moderate size, and gave up. It's much faster to set the font, foreground color, etc., on the JLabel itself instead.
    I was trying to use HTML simply to get HTML Character Entities (like &amp;) to display correctly, and it just didn't work. I wrote my own class to parse strings for HTML Character Entities, replacing them with appropriate Unicode characters, and it worked much better.
    ---Mark

  • How do i do that? MultiLine in a cell of JTable !!!

    Dear friends,
    I am trying to add multiline in a cell of JTable. For that bellow code i have written, but my statement in cell displays in a line only. Code is given bellow (copy/paste/run), could anyone help me how to do that?
    Regards..
    Jaya.
    import javax.swing.JTable;
    import javax.swing.table.AbstractTableModel;
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;
    import javax.swing.JOptionPane;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    import java.sql.*;
    public class OtL extends JFrame {
        public OtL()
          initComponents();
        private void initComponents() {
            model1 = new DefaultTableModel();
            btnClose  = new javax.swing.JButton();
            tblOt       = new javax.swing.JTable(model1);
            scrOt   = new javax.swing.JScrollPane();
            TableCellRenderer renderer = new TableRenderer();
            tblOt.setDefaultRenderer(Object.class,renderer);
            tblOt.setRowHeight(tblOt.getRowHeight()*3);
            tblOt.setBackground(new java.awt.Color(250,225,162));
            getContentPane().setLayout(null);
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            btnClose.setText("CLOSE");
            btnClose.setToolTipText("Close This Screen");
            btnClose.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED));
            btnClose.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                  System.exit(0);
            getContentPane().add(btnClose);
            btnClose.setBounds(380, 470, 110, 25);
            tblOt.setToolTipText("Operation Theatre Booking List");
            scrOt.setViewportView(tblOt);
            tableSize();
            scrOt.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0)));
            scrOt.setToolTipText("Operation Theatre Booking List");
            getContentPane().add(scrOt);
            scrOt.setBounds(15, 150, 770, 300);
            displayOtList();
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
        public static void main(String args[]) {
            JFrame j  = new OtL();
            j.setSize(800,560);
            j.show();
    /**********Code for displaying Operation Theater Booking List****Start Here*************/
        public void displayOtList(){
    Here i fire a sql query and i populate data in table.
    Sometime i get more than 1 value for some column e.g Surgery Name and Surgeon Name, so
    i want to display more than 1 value in the same cell. like bellow i have mentiond for
    5th and 6th column. But its displayin in one line only, how can i display that in multiple line!!
    I know that can be taken care with  Renderer, i tried but couldn't go through. I have written TableRenderer
    class for that, please help me what should i do in Renderer class.
          int row1=0;
          tableSize();
          DefaultTableModel model1 = (DefaultTableModel)tblOt.getModel();
          Object[] newRow = new Object[6];
            for(int i=0;i<1;i++){
              row1 = tblOt.getRowCount() + 1;
              newRow[0] = "1";
              newRow[1] = "10:10";
              newRow[2] = "11:30";
              newRow[3] = "Name Here";
              newRow[4] = "Surgery Name1 \n Surgery Name2";
              newRow[5] = "Dr. Amit \n Dr. Johnson";
              model1.addRow(newRow);
    /**********Code for displaying Operation Theater Booking List****End Here*************/
       class TableRenderer extends DefaultTableCellRenderer{
         public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean
    hasFocus, int row, int column)
           super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
          setOpaque(true);
           return this;
    /******tableSize()*****code for sizing table******start here()********/
      public void tableSize(){
        tblOt.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {},
            new String [] {"Ot No.", "Start Time","End Time", "Patient Name", "Surgery Name","Surgeon Name"}
        TableColumn column = null;
        for (int i = 0; i < 6; i++) {
          column = tblOt.getColumnModel().getColumn(i);
          if (i == 0) {
            column.setPreferredWidth(5);
          if (i == 1) {
            column.setPreferredWidth(15);
          if (i == 2) {
          column.setPreferredWidth(15);
          if (i == 3) {
            column.setPreferredWidth(130);
          if (i == 4) {
            column.setPreferredWidth(130);
          if (i == 5) {
            column.setPreferredWidth(130);
    /******tableSize()*****code for sizing table******end here()********/
        private javax.swing.JButton btnClose;
        private javax.swing.JScrollPane scrOt;
        private javax.swing.JTable tblOt;
        private DefaultTableModel model1;
    [\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    OK Filne, Thanx .. its displaying data in multiple line now.
    But still there is a problem, whenever i move mouse over the table row it returns error like bellow. I am not able to findout the reason of error. I tried to put code in try{} catch{} block to avoid this error, but still its coming. Help me.....!!!!!!!!
    java.lang.NullPointerException
            at javax.swing.text.View.getViewIndex(View.java:1060)
            at javax.swing.text.View.getToolTipText(View.java:1031)
            at javax.swing.plaf.basic.BasicTextUI.getToolTipText(BasicTextUI.java:1057)
            at javax.swing.text.JTextComponent.getToolTipText(JTextComponent.java:1533)
            at javax.swing.JTable.getToolTipText(JTable.java:2380)
            at javax.swing.ToolTipManager$insideTimerAction.actionPerformed(ToolTipManager.java:669)
            at javax.swing.Timer.fireActionPerformed(Timer.java:256)
            at javax.swing.Timer$DoPostEvent.run(Timer.java:190)
            at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:167)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:437)
            at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:150)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:131)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)my latest programe code is here :
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    public class OtL extends JFrame {
        public OtL()
          initComponents();
        private void initComponents() {
            model1 = new DefaultTableModel();
            btnClose  = new javax.swing.JButton();
            tblOt       = new javax.swing.JTable(model1);
            scrOt   = new javax.swing.JScrollPane();
            TableCellRenderer renderer = new TableRenderer();
            tblOt.setDefaultRenderer(Object.class,renderer);
            tblOt.setRowHeight(tblOt.getRowHeight()*3);
            tblOt.setBackground(new java.awt.Color(250,225,162));
            getContentPane().setLayout(null);
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            btnClose.setText("CLOSE");
            btnClose.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED));
            btnClose.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                  System.exit(0);
            getContentPane().add(btnClose);
            btnClose.setBounds(380, 470, 110, 25);
            scrOt.setViewportView(tblOt);
            tableSize();
            scrOt.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0)));
            getContentPane().add(scrOt);
            scrOt.setBounds(15, 150, 770, 300);
            displayOtList();
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
        public static void main(String args[]) {
            JFrame j  = new OtL();
            j.setSize(800,560);
            j.show();
        public void displayOtList(){
          int row1=0;
          tableSize();
          DefaultTableModel model1 = (DefaultTableModel)tblOt.getModel();
          Object[] newRow = new Object[6];
            for(int i=0;i<1;i++){
              row1 = tblOt.getRowCount() + 1;
              newRow[0] = "1";
              newRow[1] = "10:10";
              newRow[2] = "11:30";
              newRow[3] = "Name Here";
              newRow[4] = "Surgery Name1 \n Surgery Name2";
              newRow[5] = "Dr. Amit \n Dr. Johnson";
              model1.addRow(newRow);
       class TableRenderer extends JTextArea implements TableCellRenderer{
          public TableRenderer(){
            setLineWrap(true);
            setWrapStyleWord(true);
            setOpaque(true);
         public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean
    hasFocus, int row, int column)
          if (isSelected) {
            setForeground(tblOt.getSelectionForeground());
            setBackground(tblOt.getSelectionBackground());
          } else {
            setForeground(tblOt.getForeground());
          setFont(tblOt.getFont());
          if (hasFocus) {
            setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") );
              if (tblOt.isCellEditable(row, column)) {
                setForeground( UIManager.getColor("Table.focusCellForeground") );
                setBackground( UIManager.getColor("Table.focusCellBackground") );
              } else {
            setBorder(new EmptyBorder(1, 2, 1, 2));
          setText((value == null) ? "" : value.toString());
          return this;
    /******tableSize()*****code for sizing table******start here()********/
      public void tableSize(){
        tblOt.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {},
            new String [] {"Ot No.", "Start Time","End Time", "Patient Name", "Surgery Name","Surgeon Name"}
        TableColumn column = null;
        for (int i = 0; i < 6; i++) {
          column = tblOt.getColumnModel().getColumn(i);
          if (i == 0) {
            column.setPreferredWidth(5);
          if (i == 1) {
            column.setPreferredWidth(15);
          if (i == 2) {
          column.setPreferredWidth(15);
          if (i == 3) {
            column.setPreferredWidth(130);
          if (i == 4) {
            column.setPreferredWidth(130);
          if (i == 5) {
            column.setPreferredWidth(130);
    /******tableSize()*****code for sizing table******end here()********/
        private javax.swing.JButton btnClose;
        private javax.swing.JScrollPane scrOt;
        private javax.swing.JTable tblOt;
        private DefaultTableModel model1;
    }

  • Date Format problem in a JTable, help plzzz !!!

    Hi,
    i have a JTable which contains multiple date columns, and more particulary, Timestamp columns.
    I mean this format : yyyy-mm-dd hh:mm:ss.fffffffff
    I only need hh:mm:ss informations for my JTable.
    The problem is when i retrieve the datas in the JTable (which has a bean Select for model), the date column has this format : yyyy-mm-dd (only the date), and the time is not present !
    What must i do to have only a part of the timestamp data in the column ??
    Thanks in advance
    Steve

    If you want to format data in any way other than the default in a JTable, you need a table cell renderer. Sun's tutorial on how to use JTables explains them.

  • Sorting colored cell in JTable

    First, i'm sory for my bad english
    I've made a JTable that have a column contains different colored cell each row depend on value at that cell. Like some post at many forums, I'm using DefaultTableCellRenderer with overiding getTableCellRendererComponent() and calling setBackground(Color c) from that return Component object .
    At the first time data loaded into table, all is working well (each cell has their suitable color), but when I sort the table by clicking their header, the bacground color still at the fix cell (not sorted)
    Any idea for this?
    Thnks before.

    Thanx to Axel.
    Yes, right, it's working in TableSorterDemo.java
    that code coloring the cell depen on its value
    but my app need to be colored only at specific column, so i need the value of column
    i just try to modify at your code like this:
             table.setDefaultRenderer(Integer.class, new DefaultTableCellRenderer() {
                 public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                     Component cell = super.getTableCellRendererComponent (table, value, isSelected, hasFocus, row, column);
                     cell.setBackground(Color.white);
                     if(value instanceof Integer) {             
                         if ((new Integer(5)).equals(value)) {
                             cell.setBackground(Color.yellow);
                         } else if((new Integer(3)).equals(value)) {
                             cell.setBackground(Color.green);
                         } else if((new Integer(20)).equals(value)) {
                             cell.setBackground(Color.red);
                     if(column == 0){ //not working, n it should not :D
                    cell.setBackground(Color.red);
                     return cell;
    but, didn't work
    so i set the CellRenderer using column approach in my app, like this:
    DefaultTableCellRenderer leftCellRenderer = new DefaultTableCellRenderer() {
                @Override
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                    Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                    super.setHorizontalAlignment(SwingConstants.LEFT);
                    return cell;
            DefaultTableCellRenderer centerCellRenderer = new DefaultTableCellRenderer() {
                @Override
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                    Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                    super.setHorizontalAlignment(SwingConstants.CENTER);
                    return cell;
            DefaultTableCellRenderer coloredCellRenderer = new DefaultTableCellRenderer() {
                @Override
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                    Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                    super.setHorizontalAlignment(SwingConstants.CENTER);
                    if (value.equals(" ")) {
                        cell.setBackground(Color.GREEN);
                    } else {
                        cell.setBackground(Color.RED);
                    return cell;
            myTable.getColumnModel().getColumn(1).setCellRenderer(leftCellRenderer);
            myTable.getColumnModel().getColumn(0).setCellRenderer(centerCellRenderer);
            myTable.getColumnModel().getColumn(2).setCellRenderer(centerCellRenderer);
            myTable.getColumnModel().getColumn(3).setCellRenderer(centerCellRenderer);
            myTable.getColumnModel().getColumn(4).setCellRenderer(coloredCellRenderer);And all works fine :-)
    Thanks.

Maybe you are looking for

  • Acrobat hangs while creating merged PDF in acrobat 9.0

    Hello, We are facing issue with Acrobat 9.0 while combining MS office docs with PDF ( option of Merge files into single pdf). Whenever we combine word or excel docs with pdf, Acrobat hangs. Acrobat has to be terminated to clear the session. The optio

  • Charms bar doesnt work

    After updating my os from win 8 to win 8.1 I started experiencing problems with charms bar. problem 1 :wheni point my mouse pointer to right edge of the screen charms bar doesnot appear unless I restart windows explorer in task manager.Even start but

  • My iMac password is not working

    Hello, I'm using my iMac as hotspot and it's visible to other devices. When I try to connect it asks me for the iMac password but I get a message that it's incorrect. I  changed the password but still the same problem occurs. Than you, Mustapha

  • Mac Mail constantly downloading messages (iCloud)

    I recently did the mobileme to icloud swtich to keep my me.com email. Since Snow Leopard doesn't have an iCloud option and the MobileMe account option no longer works, I had to switch to create a new IMAP account with all of iCloud's server info. Eve

  • Does a Canon S80 work with iPhoto 6

    I just ordered a Canon S80 digital camera. The Canon website says that they are still testing this model for Tiger compatibility. Does anyone have any experience using this camera with iLife 06?