Right Justify a column in a JTable

Hello,
I formatted a decimal number and want to put it into a column in a JTable. Unfortunately, the value is being left justified. How do I make the data for the column right justitified?

Thank you both for your answers. I had looked in the tutorial, but could not find the area for justifications. I did have a table model with a getColumnClass too, but didnt realize that I didnt have to use the actual data type's class to render the justification.
Looking back at the tutorial, I now find that ImageIcon is supposed to be used for centering, but this didnt work. It wiped out the data for the column I tried to use it on rather than justifying it left or right. Any ideas how to get centering to work?

Similar Messages

  • Right-justify number columns in BC4J

    I have several JSP pages that I am using BC4J tags in. I want to right justify all dollar columns. In addition, I want some columns to have a default width regardless of the data in them. For instance, even if a column has 'Test' in it, I want it to have a display width of 50.
    How can I accomplish these two things?
    Thanks,
    Brett

    Sounds like you might want to add properties to the attributes in your VO. If you set up some properties to hold values for alignment and width for each column, you can just interogate these values when you render the JSP and writre them into the HTML.
    Matt

  • Right-justify column name

    Hello Gurus
       I would like to right-justify the column heading. How can I do this? Specifically, this refers to the Quantity field in the Items assignment block in the Opportunities Overview screen.
    Regards,
    Sowmiya

    Try using LPAD like
    select lpad(object_name,30) from all_objects where rownum < 20;

  • Styled Text right justify for numbers

    I have a Sytled Text element in my UI that I use to store numbers and i would like to right justify the column so that the values line up properly. I'm using 11.5.10.

    i see it gets rendered this way
    <td class="x11 x50">
    < span ...... 10.0 </span>

  • How to get search help results in RIGHT-JUSTIFIED column

    I am writing a search help with search help exit. Therefore, I use a table lets say tabA. I don't need all fields of tabA but need some further fields which I fill during exit.
    tabA does not have currency or number fields.
    I need a currency field and use a char20 field of tabA instead. filling of this field and showing results is o.k., but of-course it is shown left-justified.
    I did not find any fields of shlp-fielddescr which sounds like left/centered/right-alignment. Another try was to fill char20 field with leading '_' signs - that looked terrible and was not right-justified either, because of not fixed-size font.
    Let's resume: there is no number or currency field which I can use. The shown results appear in a column of not fixed-size font.
    Any other idea?

    Hi, I have the same problem. Did you get to resolve it? . Thanks

  • How to align Hgrid column(messagestyledtext) header text to right justified

    Hi All,
    I have a Hgrid table and i am using five columns in hgrid table.. I need to display column header text right justified. but by default it is left justified.
    Can any one tell me how to do it..
    Its very urgent.. Please help me out..
    Regards,
    Babu

    Use
    OAHGridBean GeneralHgrid=(OAHGridBean)webBean.findChildRecursive("<hgrid item name>");
    GeneralHgrid.prepareForRendering(pageContext);
    DataObjectList tableColumnFormats =GeneralHgrid.getColumnFormats();
    DictionaryData tableColumnFormat = (oracle.cabo.ui.data.DictionaryData)tableColumnFormats.getItem(pageContext.findChildIndex(GeneralHgrid, "<item id of item attached in hgrid column>"));
    tableColumnFormat.put(COLUMN_DATA_FORMAT_KEY, <enter format>);
    see below:
    �� TEXT_FORMAT (textFormat)- column content is Start justified.
    �� NUMBER_FORMAT (numberFormat)- column content is Right justified.
    �� ICON_BUTTON_FORMAT (iconButtonFormat)- column content is center justified.
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Wrting data right justified column

    Hi
    In my application I am using producer consumer loop architechture. In the consumer loop i am writn data from a queue to a file. I want to write data in a certain format to analyze in another program.   Now when i write dat to a file it writes left justified in six columns. I want it to write to file like the one i have attached. Can somebody tell me how?
    Attachments:
    data.PNG ‏53 KB

    Ideally, you would just use a tab as delimiter and change the justification in the other program as needed. For example in MS word you can define how the tabs are justified.
    If you want the data right justified in simple text displays (wordpad, notepad), you just need to ensure that the field width is sufficient for the widest data.
    Try e.g. a format specifier of "%#15_6f' (and make sure that you use a fixed width font for display!)
    Message Edited by altenbach on 10-08-2008 09:53 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    formatRight.png ‏15 KB

  • JTables - Right Aligning certain columns

    Hi!
    Im having a major problem! I am using JTable in my prog, but Im finding them very difficult to customise. I am wanting my JTable to have certain Columns(for monetary values) right aligned, as this looks far better when dealing with currency. I have tried implementing this class on my JTable:
    package accpick.overrides;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.*;
    class MyRenderer implements TableCellRenderer
         TableCellRenderer old_renderer;
         MyRenderer(TableCellRenderer old_renderer)     
              this.old_renderer = old_renderer;
         public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasFocus,int row,int column     )     
         // use the old renderer to render the cell          
         Component c = old_renderer.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column);
         if(column == 3||column == 4||column == 6)          
              //align right
         // set all other cells to normal          
         else          
              //align left
         return c;
    The problem with this is that getTableCellRendererComponent() returns a Component, and Component does not seem to have a method to align, but JComponent does(setAlignmentX())
    Please can someone help!!!Am i on the right track or am i going about it totally the wrong way?
    THanks
    Nitron999

    Thanks everyone! Your advice got me past the compiler! But Im still having the problem of right aligning the columns! Was my code on the right path, or am i farting in the wind here?
    Does anyone know of any relatively well structured way of doing this?

  • How can I add custom right-click-menu to column headers in JTable?

    Can anyone point me to a topic on how to customize a popup menu for column headers in JTable? Specifically, I want to add things like "auto-size column" and "hide column".
    Thanks,
    Matt

    Right-click on your table.  Then go to Advanced->Runtime Shortcut Menu->Edit.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Left and right justifiation in alv grid

    I m using alv grid to display a tbale.I have to justify one perticular cell depending on value.So i have to first check the value of that field in itab and then justify right or left accordingly.
    Therefore , i cnt use just field of field catalog as im not goin to justify whole column.
    I tried to save justified value in itab  and then display in alv but alv doesnt display white space charaters in start and end.
    Could you help me with this topic.
    regards

    hii,
    i think this is not possible.

  • Sort options right justified in list view

    New to Maverick's, but I can't get my finder window to "stick" with the layout of the "sort options". My biggest beef is that I have the "Name" sort far left followed by "Date modified", etc.. yet every day in every new finder window, the 2nd sort jumps to right justified. I want this sort option to stick to the left alongside name. I use large monitors and scrolling over everytime to drag the sort modifier to the left is frustrating. Is there a solution?

    My guess would be the Images folder (Pictures in English) is designed to have the special, contextual grouping types.
    I don't know why they couldn't make them available in the dropdown menu, also, but they're not.
    I did a little testing and found if I called it Pictures unsorted, the options were available, but if I called the folder unsorted Pictures, they weren't.
    Try naming the folder starting with Images
    Edit: If I select the dimension and resolution column headers in the folder, then change the name of the folder, the columns are retained.

  • Simulating one column using two columns in a JTable

    What I need to do is "join" the two first columns of a JTable...
    What do I mean by saying "join" ?
    I want to make dissapear the right border of the first column, and the same thing for the left border of the second column, also do both things for the column headers of that two columns.
    All that to simulate having one column when there's actually two differents columns.
    How can i do that ? Thanks !

    Make a TableModel that filters your original table model.
    See JTable.setModel.
    public class MergedColumnsTableModel extends javax.swing.table.AbstractTableModel
         javax.swing.TableModel model;
         int[] columnSpans;
          * Assume for simplicity that model does not change (no columns inserted/deleted).
         public MergedColumnsTableModel(javax.swing.TableModel model) {
              this.model = model;
              columnSpans = new int[model.getColumnCount()];
              for (int columnIndex = 0; columnIndex < columnSpans.length; ++columnIndex) {
                   columnSpans[columnIndex] = 1;
         public void merge2(int columnIndex) {
              int leftSpan = columnSpans[columnIndex];
              int rightSpan = columnSpans[columnIndex + leftSpan];
              columnSpans[columnIndex + leftSpan] = 0;
              columnSpans[columnIndex] += rightSpan;
         public int getRowCount() {
              return model.getRowCount();
         public int getColumnCount() {
              int n = 0;
              for (int i = 0; i < columnSpans.length; ++i) {
                   if (columnSpans[i] != 0) {
                        ++n;
              return n;
         public Object getValueAt(int row, int column) {
              int n = 0;
              for (int i = 0; i < columnSpans.length; ++i) {
                   if (columnSpans[i] != 0) {
                        if (n == column) { // We are at the column
                             return model.getValueAt(row, i);
                        ++n;
    }

  • Context Help in diferents Columns in a JTable

    I want to put Context Help in the diferents columns in a JTable (in columns, in headers or cells); but I don't know how I can do it.
    Please, if somebody can help me, or simply say me that this is not possible (if is really impossible).

    Carlos,
    You can write your own F1 listener for JTable (or if you prefer a right click help menu option then a mouse listener). In the listener determine what cell has focus or is clicked over. From this generate a help topicID. Then call showTopic on the CSHManager or Help.
    Note the table has an editor component (e.g., JTextField), the make sure that the correct topicID is associated with this editor component.
    Cheers,
    Craig Cummings.
    Oracle Help Team

  • Show hidden columns in a JTable

    Hi,
    I have a requirement for hiding some columns of a JTable and showing them back based on user actions.
    I have gone through some topics about hiding columns. which can be done by table.removeColumn();
    But when I use table.addColumn(); it adds the column at the end of the table.It should add in the same location as the previous column.
    How to show /reveal the hidden column back?.

    * Hide_Columns.java
    * This code contains a table model that allows you to
    * specify the columns to be hidden in a boolean array.
    * To use the model:
    *       model = new MyTableModel(data, columnNames);
    *       table.setModel(model);
    * The most important method in the model is "getNumber()", which converts a column number
    * into the number corresponding to the data to be displayed.
    * Visible columns can be dynamically changed with
    * model.setVisibleColumns(0, column0.isSelected());
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class Hide_Columns extends JFrame {
        public Hide_Columns() {
            setTitle("Hide columns");
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            model = new MyTableModel(data, columnNames);
            table.setModel(model);
            getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
            for( int i=0; i<4; i++ ){
                final JCheckBox columnX = new JCheckBox("Column "+i);
                columnX.setSelected(true);
                final int col = i;
                columnX.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        model.setVisibleColumns(col, columnX.isSelected());
                toolBar.add(columnX);
            getContentPane().add(toolBar, BorderLayout.NORTH);
            setSize(400,300);
            setLocationRelativeTo(null);
            model.addRow(new Object[]{null,null,null,null});
            model.setValueAt("test0",0,0);
            model.setValueAt("test1",0,1);
            model.setValueAt("test2",0,2);
            model.setValueAt("test3",0,3);
        public static void main(String args[]) { new Hide_Columns().setVisible(true); }
        private JTable table = new JTable();
        private  JToolBar toolBar = new JToolBar();
        private   MyTableModel model;
        /** This is the data of the table*/
        private  Vector<Object> data = new Vector<Object>();
        /** Column names */
        Vector<String> columnNames = new Vector<String>();{
            columnNames.addElement("0");
            columnNames.addElement("1");
            columnNames.addElement("2");
            columnNames.addElement("3");
    class MyTableModel extends DefaultTableModel {
        /** Shows which columns are visible */
        private   boolean[] visibleColumns = new boolean[4];{
            visibleColumns[0] = true;
            visibleColumns[1] = true;
            visibleColumns[2] = true;
            visibleColumns[3] = true;
        public MyTableModel(Vector<Object> data, Vector<String> columnNames){
            super(data, columnNames);
        protected void setVisibleColumns(int col, boolean selection){
            visibleColumns[col] = selection;
            fireTableStructureChanged();
         * This function converts a column number of the table into
         * the right number of the data.
        protected int getNumber(int column) {
            int n = column;    // right number
            int i = 0;
            do {
                if (!(visibleColumns)) n++;
    i++;
    } while (i < n);
    // When we are on an invisible column,
    // we must go on one step
    while (!(visibleColumns[n])) n++;
    return n;
    // *** METHODS OF THE TABLE MODEL ***
    public int getColumnCount() {
    int n = 0;
    for (int i = 0; i < 4; i++)
    if (visibleColumns[i]) n++;
    return n;
    public Object getValueAt(int row, int column) {
    return super.getValueAt(row, getNumber(column));
    public void setValueAt(Object obj, int row, int column) {
    super.setValueAt(obj, row, getNumber(column));
    public String getColumnName(int column) {
    return super.getColumnName(getNumber(column));

  • How to set column alignment in JTable

    I make a table with JTable(Vector a, Vector b).
    I don't know how to set the alignment to right while the column type is Integer or Long.
    Do i have to use JTable(Object[][] a, Object[] b) ?

    Well , you can configure the alignment when you are creating the column, like
    for (int i=0; i<7; i++){
    //Size of cell
    int colunaTam = 50;
    //Define Allingment
    int cellAlinhamento = 4; //Right Aligment
    //Column
    javax.swing.table.TableColumn coluna;
    BusinessObjects.CellColorRenderer renderer = new BusinessObjects.CellColorRenderer();
    //Define alingment in cell render
    renderer.setHorizontalAlignment(cellAlinhamento);
    coluna = new javax.swing.table.TableColumn(i, colunaTam, renderer, null);
    ivjJTableDespachos.addColumn(coluna);
    Hope i help you...
    Ice

Maybe you are looking for

  • External Hard Drive Deleted Whole Folder When Moved (error -36)

    I have a Free Agent Pro external hard drive (1 Terabyte). I just moved a folder, and it deleted all the contents. Now I have the error: "The Finder cannot complete the operation because some data in "[Folder Name]" could not be read or written. (Erro

  • MSI 94GT MD 512 no audio to TV via HDMI

    Greetings,    I have an MSI 94GT MD512 (aka n9400GT MD 512) video card installed in an Asus N4L-VM DH motherboard, connected to a Sony Bravia KDL-26L5000 TV via HDMI. Video card S/PDIF internal cable connected to S/PDIF Out and Ground connectors on m

  • Help re error message - file not found!

    I have recently transferred my library from my old PC to a new laptop.  This seemed to go ok and the files are showing up in my new library.  However I have just tried to add some files to my iPhone and I am now getting an error message when I try to

  • Blurry Text, Screen Jump/Shift, Waterlogged Look at Top??

    I've been having some problems with my 23" Monitor lately. I noticed recently when brought up in firewire the top of the monitor has a waterlogged type stain in the pixels, they aren't dead but discolored. Today i have been having worse problems thou

  • Document not saved

    When i use exel and add a comment to a cell "Document not saved" some times comes up. To get past this i have to delete the coment and re do it, it then some times saves. I dont know what I am doing wronge and what I am doing right because it does so