How to customise Diplay of DateTime in JTable/TableModel

hi all,
If a datetime field in a database table stored as "yyyy-MMM-dd hh:mm:ss". Is it possible for swing JTable/TableModel display the DateTime into a format like "MMM-dd-yyy"?
Please help. :)
regards,
Elvis
scjp

hi Elvis,
You can display the DateTime in JTable with the format like "MMM-dd-yyyy". All you have to do is grab the date from the database then convert it to the format you like before adding to the table.
Here is the code to convert date format:
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("MMM-dd-yyyy");
String dt = sdf.format(d); // d - the date from database
Hope it helps.
Alex

Similar Messages

  • How can i add rows to a JTable at run time ??????

    hi there
    how can i add a row to a JTable at run time? and display the table after the change? thank you.

    For adding or removing the rows from the JTable, you have to use the methods on the table model. I would show you a simple implementation of table model.
    public class MyTableModel extends AbstractTableModel {
    private ArrayList rowsList = null;
    private String [] columns = { "Column 1" , "Column 2", "Column 3"};
    public MyTableModel() {
    rowsList = new ArrayList();
    public int getRowCount() {
    return rowsList.size();
    public int getColumnCount() {
    return columns.length;
    public void addRow(MyRow myRow) {
    //MyRow is any of your object.
    rowsList.add(myRow);
    fireTableDataChanged();
    public void removeRow(int rowIndex) {
    rowsList.remove(rowIndex);
    fireTableRowsDeleted(rowIndex, rowIndex);
    public Object getValueAt(int row, in col) {
    MyRow currentRow = (MyRow)rowsList.get(row);
    switch (col) {
    case 0:
    //return the value of first cell
    break;
    case 1 :
    //return the value of second cell
    break;
    case 2 :
    //return the value of third cell
    break;
    }Then create the table using the TableModel using the constructor new JTable(TableModel) and then when you want to add/remove a row from the table, call myTableModel.addRow(MyRow) or myTableModel.removeRow(rowIndex)....I hope that this solves your problem.

  • 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

  • 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 customise Excise duty

    How to customise Excise duty, Insurance, cess condition type in Pricing procedure? Explain in detail

    Hi
    Excise duty - JMOD (statistical) and JEX2 (posted) is the Ctyp ( this is standard SAP)
    CESS - JCEX and JCEX ( one is statistical and the other is posted)
    Reward if it helped!
    Chandru

  • How to customise "Excise challan *** Commercial Invoice" in SAP

    How to customise "Excise challan *** Commercial Invoice" in SAP? Explain in detail

    Hi Gopala,
    Please Create 2 differnet Billing documents types for Commercial Invoice and Excise Chanllan and Ensure that Copy controls to be maintianed for the both the Billing types.
    Hope this Clarifies your Doubts and Please Reward If Really Helpful,
    Thanks and Regards,
    Sateesh.Kandula

  • How to customise the backdrop in photo booth application?

    how to customise the backdrop in photo booth application?

    If you’re using Photo Booth in full screen, move the pointer to the top of the screen, then click the Exit Full Screen button.
    If you’re viewing a photo or a video, click the View Video Preview button.
    Click the Effects button.
    Browse through the backdrops until you reach User Backdrops.
    Drag a photo or video to one of the User Backdrop frames. You can drag a picture or video from your desktop, the Finder, iMovie, iPhoto, or Safari.

  • How to subtract time from dateTime in xquery?

    How to subtract time from dateTime in xquery??
    In ALDSP i tried to use the function xf:add-days but it is showing an error saying invalid function name. I think this namespace is not valid for ALDSP. Is there is any way to add this function in ALDSP???

    xquery functions and operators documentation is here :
    http://www.w3.org/TR/xpath-functions/
    It sounds like you want to ..
    op:subtract-dayTimeDuration-from-dateTime
    this is not an xquery function that you can call, it is an xquery operation defined by the specification
    I believe you can simply use the '-' operator to use that operation.
    <newDateTime>
    { $myDateTime - $myTime }
    </newDateTime>

  • How to customise charting styles?

    Hi,
    I'm currently looking for a way to customise the styles
    available in cfchart. I have to place 9 charts on an A4 page in
    landscape i.e. 3 rows of 3 charts, each of size width 280 and
    height 190.
    Is there anybody who can please help me with the following?
    1. If you choose a particular size in the fontsize attribute
    of the cfchart tag, all labels have this size. Is there a way to
    style the fontsize of the x-axis data labels to be smaller,
    independently of the fontsize of the remaining labels? Something
    similar to MS Excel.
    2. Is there a way to increase the graph area? Ok, you would
    say make the fonts smaller. But at a certain fontsize, e.g. below
    Arial Narrow font size 8, it is barely readable. I want to be able
    to resize the graph area e.g. like in MS Excel or Crystal Reports.
    Is there a way to do this?
    3. Can the position of the legend be changed? By default it
    appears in the centre on top of the charts. Is there a way to
    position it differently?
    You can imagine with the space available to place 3 charts of
    width 280px next to each other, the display will definitely suffer,
    especially if e.g. the x-axis data labels are quite long.
    In fact, the only things that I've already changed are:
    1. x-axis orientation to vertical in default.xml
    2. using Arial Narrow size 8
    Your help will be greatly appreciated.
    Thanks and regards,
    Yogesh Mahadnac

    Hi,
    Ok, I've used the webcharts.bat file in the
    "CFusionMX7\charting" directory to create a style called
    myStyle.xml which I've saved in the "CFusionMX7\charting\styles\"
    directory. See code below.
    However when I try to use this style in the cfchart
    style="myStyle" the x-axis font
    DOESN'T display font size 8!!!
    I need to
    MANUALLY set the font attributes.
    <cfchart font="Arial Narrow" fontsize="8">
    Any idea why this is so, or any idea how to customise the
    charts further?
    Thanks and regards,
    Yogesh Mahadnac
    <?xml version="1.0" encoding="UTF-8"?>
    <frameChart is3D="false" font="Arial Narrow-8"
    isMultiline="true">
    <frame xDepth="6" yDepth="6" outline="black"
    gridColor="#CCCCCC"/>
    <xAxis>
    <labelFormat pattern="#,##0.###"/>
    <parseFormat pattern="#,##0.###"/>
    <labelStyle orientation="Vertical" color="black"/>
    <titleStyle font="Arial Narrow-8"/>
    </xAxis>
    <yAxis scaleMin="0">
    <labelFormat pattern="#,##0.###"/>
    <parseFormat pattern="#,##0.###"/>
    <labelStyle color="black"/>
    <titleStyle font="Arial Narrow-8" foreground="black"/>
    </yAxis>
    <yAxis2>
    <labelFormat pattern="#,##0.###"/>
    <parseFormat pattern="#,##0.###"/>
    <labelStyle color="black"/>
    <titleStyle font="Arial Narrow-8" foreground="black"/>
    </yAxis2>
    <topYAxis>
    <labelFormat pattern="#,##0.###"/>
    <parseFormat pattern="#,##0.###"/>
    <labelStyle color="black"/>
    <titleStyle font="Arial Narrow-8" foreground="black"/>
    </topYAxis>
    <topYAxis2>
    <labelFormat pattern="#,##0.###"/>
    <parseFormat pattern="#,##0.###"/>
    <labelStyle color="black"/>
    <titleStyle font="Arial Narrow-8"/>
    </topYAxis2>
    <dataLabels font="Arial Narrow-8"/>
    <legend spacing="3" valign="Top" halign="Right"
    useMarkers="true"
    font="Arial Narrow-9">
    <decoration style="None"/>
    </legend>
    <elements outline="black" shapeSize="40" lineWidth="2"
    fixedWidth="2">
    <morph morph="Grow" stage="Cols"/>
    </elements>
    <table cellPadding="0" border="None">
    <decoration style="None"/>
    </table>
    <title spacing="2" font="Arial Narrow-8-bold"/>
    <paint isVertical="true" min="47" max="83"/>
    </frameChart>

  • How to customise basic price control

    how to customise basic price control

    Hi,
    in table EKKO u will get the the field EBELN, which is for purchasing document. here if u filter this document with value "F" in field BSTYP (Purchasing document category) u will get the PO numbers.
    next with this PO number u have to go to table EKPO, here u will get the material number MATNR and NETPR (Net price in purchasing document (in document currency)), NETWR (Net order value in PO currency), BRTWR (Gross order value in PO currency).
    hope it will resolve ur issue.
    regards
    jash

  • How to resize a cell in a JTAble

    Hi everyone,
    i have a question how can be done that a column of cells will have an specific size and that other column will be smaller or bigger than the other

    Hi,
    If you mean how to set the columns of your jtable to be of different widths, it can be done as follows:
          TableModel tm =table.getModel();
          int colcount = tm.getColumnCount();
          TableColumnModel tcm = table.getColumnModel();
          for(int s=0;s<colcount;s++) {
                tcm.getColumn(s).setPreferredWidth(150);
                tcm.getColumn(s).setMinWidth(150);
          }Just set the width you want based on the column no in the code above.
    cheers,
    vidyut
    http://www.bonanzasoft.com

  • How to customise Siebel Attachment Content Check-In Form?

    I've customised my search form using the rules and now all the field from search form appears in the check-in form. How to customise fields list for the check-in form?
    Thanks in advance.

    Hi jiri.machotka
    I Know this link but what i want to do is generating dynamically a sub form (in checkin form) depending on choice
    For example when my choice is Person it generate a sub form containing
    Name (input with its label)
    Firstname
    Lastname
    Age
    Regard
    CABDiop

  • How can i make hidden column in JTable

    hi, how can i make hidden column in JTable,
    basically i have a ID field in JTable, i have to use this ID , but i also dont want to show this ID in JTable.
    any idea how ??

    staiji its not working
    i did this :
    first :
    TableColumnModel columnModel =
    usersTable.getColumnModel();TableColumn column =
    columnModel.getColumn(1);
    usersTable.removeColumn(column);
    then when i trying to get this :
    Integer userId =
    (Integer)usersTable.getValueAt(UserBrowser.this.usersTa
    le.getSelectedRow(), 0);
    it not give me ID column's value .
    i have a column in JTable like :
    ID | Username | First name | Last name
    i want to hide ID column , but get this ID's value
    when user clicks on JTable row.Hi, if you would read the documentation about JTable.getValueAt(...) you will find, that there is a significant difference between this method and the datamodels getValueAt(...) method. JTables getValueAt(...) method interprets column-index as index in its TableColumnModel - in your TableColumnModel there is no column any longer that holds ID values, therefore you were not able to get it by JTable.getValueAt(...). Do not use these methods for the purpose you want it for - you will also get the wrong values, if the user has repositioned columns - the column index is always interpreted as index in the currently used TableColumnModel and IS NOT A MODELINDEX.
    greetings Marsian

  • How to insert rows & columns into a jTable???

    helloo there...
    How to insert rows & columns into a jtable???
    your reply is greatly appreciated....
    -=samer=-

    Yes!thanks...
    But what i want is how to set the number of rows and the number of columns...and i don't know how to setColumns and rows....any idea?
    the user will input number of rows and columns in a jtextfield....
    Please rply...

  • How can I set column width in JTable?

    How can I set column width in JTable?

    Also, read the JTable API before posting questions. You will find a link to the Swing tutorial on "How to Use Tables", which contains an example of doing exactly this.

Maybe you are looking for