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?

Similar Messages

  • Right Align in Columns

    Okay, so I'm working on an index manually (because this is a second index for a single book) and am having some trouble with the alignment of paragraphs within a three-column page.
    Here's what my paragraph style looks like:
    And here's what the actual paragraph looks like:
    I cannot for the life of me figure out why that is a three line paragraph! Anyone have any suggestions?

    I looked at the file and you're right about InDesign allowing extra space for the page numbers. I starting the page numbering at 10001, and guess what? InDesign fit 5 numbers on the first line, using the full width of the column (2-, 3-, and 4-digit numbers also fit 5 on the line). Strangely, when I changed the first page to a six-digit number, it still tried to fit 5 numbers on the first line, all squeezed together. It seems as if InDesign wants to allow for a 5-digit page number cross-reference, at least using Gill Sans. I changed the font to Gill Sans Condensed, and InDesign wanted to fit 7 numbers per line, no matter how many digits.
    It seems to be related to the cross-reference referring to a page number; when I changed the cross-reference format to "Paragraph Text," InDesign happily flowed the text in position, using the full column width.
    Sorry I don't have a solution for you, but at least the problem is consistent and reproducible. Maybe someone else will come by with another idea. Very strange.
    -Bill

  • Right alignment of Number Field in OAF Page

    Hi,
    I need to right align the column of the table which is of number type in OAF page. I have extended the VO of that page to add new columns. After VO extension i added the column to the page via personalization and gave the reference of view attribute name as per Extened VO. I have set the following properties for that column
    Item Sytle- Message Style Text
    Data Type- Number
    Nowrap=false
    Vertical Alignment=Middle
    View Attribute = Prior (same as Extended VO's column)
    View Instance = XXPayEmpAccrualActionInfoVO
    I need to set the value of this newly added column right align which is currently set as left align by default.
    I have tried the following links from OTN
    Re: Q: How to format number using personalization?
    Right align number field
    but while controller extension i m getting the following error-
    Message not found. Application: FND, Message Name: FND_VIEWOBJECT_NOT_FOUND. Tokens: VONAME = XXPayEmpAccrualActionInfoVO; APPLICATION_MODULE = oracle.apps.pay.selfservice.payslip.US.server.PayPayslipAM;
    The extended controller code is -
    public void processRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processRequest(pageContext, webBean);
    OATableBean tableBean = (OATableBean)webBean.findIndexedChildRecursive("PayPayslip4Ss");
    tableBean.queryData(pageContext, true);
    tableBean.prepareForRendering(pageContext);
    DataObjectList aColFormat01 = tableBean.getColumnFormats() ;
    oracle.cabo.ui.data.DictionaryData ColFormat01 =(oracle.cabo.ui.data.DictionaryData)aColFormat01.getItem(pageContext.findChildIndex(tableBean, "Prior"));
    ColFormat01.put(COLUMN_DATA_FORMAT_KEY,NUMBER_FORMAT);
    Please can anyone provide me some pointer here..this is really urgent.
    Thanks in advance
    Renu
    Edited by: Renu Gupta on Jun 14, 2010 5:15 AM

    Hi Renu,
    Use the following code:
    OAMessageStyledTextBean origContSumBean = (OAMessageStyledTextBean)webBean.findIndexedChildRecursive("<FieldName>");
    if(origContSumBean!=null) {
    origContSumBean.setAttributeValue(CURRENCY_CODE,new OADataBoundValueViewObject(origContSumBean,"CurrencyCode"));
    Here CurrencyCode should be a view attribute in the VO associated to the items in the region.
    Regards
    Sumit

  • How to set Right Alignment for a JTable column

    Hi,
    I am using a JTable for displaying database records using AbstractTableModel. It works fine. But, for the numeric fields I want to make records right aligned using setHorizontalAlignment. I tested with TableColumn.setHorizontalAlignment but it ends up with an error. Is there a solution? Please help me. Thanks in advance.
    bhuvana.

    In you table cell renderer you can specify the alignment of the text.
    public class MyTableCellRenderer extends JLabel implements TableCellRenderer
    public MyTableCellRenderer
    setOpaque(true);
    setBackground(Color.white);
    public Component getTable.....(JTable table,Object value,......) //fill all these things
    setFont(table.getFont());
    if(value instanceof Float)
    setHorizontalAlignment(SwingConstants.RIGHT);
    setText(value);
    return this;
    This would set all the Floats to RIGHT alignment.
    Thanks,
    Kalyan

  • Table numbers in a column to Right alignment

    Hi All,
    I have a table like the below.
    Age (Years)
    1985
    1998
    2007
    1–4
    52
    35
    29
    5–14
    26
    20
    15
    15–24
    102
    82
    80
    25–44
    167
    161
    144
    45–64
    875
    680
    661
    65–74
    2,848
    2,495
    2,059
    75–84
    6,399
    5,703
    5,164
    Over 85
    15,224
    15,111
    12,947
    I want to decimal align the 2nd,3rd,4th column using javascript.
    Paginators are manullay using tab stops and adjusting the "Align to Decimal Tab"
    But I want to do it in javascript
    Help me...

    Hi, Maheshwara:
      Your question's a bit confusing, because your example does not show any decimal points! Perhaps it would be good for you to show a screenshot from InDesign with Hidden Characters enabled and the Tab ruler visible so we can see what is going on.
    What do you want to do, though? My guess is you want to right-align the text, then go through and find the entry with the most characters to the right of a decimal point and set a decimal tab based on that entry, and apply it to the entire column. Sounds pretty easy!
    Are you stuck? What's the problem? How far have you gotten? Do you know Javascript?

  • Need Amount column to be Right Aligned in LOV asap

    Hi,
    I have a amount column in a custom LOV which needs to be right aligned. but in LOV, by default all columns come as left aligned..Pls provide a solution asap.
    Thanks,
    Puneet

    The column alignment depends on the type of data it displaying. Number columns are right aligned and string column are left aligned. this is default behaviour.
    Change datatype of column amount to Number. It will allign right.
    Thanks,
    Ram

  • Column's Right Alignment goes out with CR in format Mask like NNN,NN0.00CR

    I am working in Reports 6i. For a numeric calculated column, I give format mask NNNN,NNN,NNN,NN0.00CR. Due to CR, right alignment of the column goes out. That is rows for which CR is NOT printer are also aligned at right. A blank space should be left at the end of every row when no CR is printer. In this way numeric data is right aligned and readability is not disturbed.
    Pl. help.
    Thanks in anticipation.

    I am working in Reports 6i. For a numeric calculated column, I give format mask NNNN,NNN,NNN,NN0.00CR. Due to CR, right alignment of the column goes out. That is rows for which CR is NOT printer are also aligned at right. A blank space should be left at the end of every row when no CR is printer. In this way numeric data is right aligned and readability is not disturbed.
    Pl. help.
    Thanks in anticipation.
    Muhammad,
    I tried this on 6.0.8.14.2 version of Reports 6i and it aligned properly (i.e., spaces where present for those values without CR). I originally had the Arial font which as you know is not a fixed font and in this case, the spacing was not exact. I switched to Courier and the output was much more readable for the numeric values, especially with the spacing.
    Regards,
    Jim Safcik
    Thanks Jim Safcik. I changed the font of that column to Courier and it resolved the problem. But I am using Times New Roman font which creates above alignment problem.
    It would be nice if we have an other solution which is NOT font dependent.
    However I appreciate your guidance and knowledge.
    Pl. guide.
    Thanks.

  • Right alignment for OO tree column

    Hi experts,
    how can i align the data of type characters in the OO tree alv display? i want to align it to the right.
    Thanks.

    Hello,
    Set Alignment of the Text in the Column
    You are able to set where the content of a column will be put:
    ·        Left aligned
    ·        Centered
    ·        Right-aligned
    You are able to change the alignment of text in the design object (header and footer area of page or list) and in the ALV output.
    Use the method CL_SALV_COLUMN SET_ALIGNMENT
    Check
    http://help.sap.com/saphelp_nw2004s/helpdata/en/5e/88d440e14f8431e10000000a1550b0/frameset.htm

  • Right Aligned Float in JTable

    I am trying to insert floats in two or more cells but i don't how to right align it. I searched thru the tutorials but found some info only about right alignment of Integer type. Further i want to restrict entry of decimals i mean some cells (in a column) should accept 2 or 3 decimals.
    Is there any material to read more about this or the gurus out here can help me with their insights.
    TIA
    Shomal

    You must to have the model, like next code:
            TableColumnModel columnModel = tableView.getColumnModel();
            TableColumn colorColumn = columnModel.getColumn(0); //get the desire column
            DefaultTableCellRenderer colorColumnRenderer = new DefaultTableCellRenderer();
            colorColumnRenderer.setForeground(Color.red); //to change the color
            colorColumnRenderer.setBackground(Color.gray);
            colorColumnRenderer.setHorizontalAlignment(JLabel.RIGHT); //here you aling...
            colorColumn.setCellRenderer(colorColumnRenderer);When the cell is editing if you want the same aling also you must to define the aligned like that
    JTextField texto= new JTextField();
    texto.setHorizontalAlignment(JTextField.RIGHT);
    colorColumn.setCellEditor(new customEditor(texto));
    This works for me...

  • Right/Left align the column header.

    Hi All,
    Is there any option for align the column header irrespective to the column contents.
    There is an option for align data inside the column.But I can't find any for the column headers.
    Give me an idea.
    Thanks
    Swapna

    use the
    align="Left" or "right"and use the "margin-left:10px" for the component.
    for example
    <af:column sortable="false" width="80"
                             headerText="#{viewcontrollerBundle.UNIT_PRICE}" id="c8" align="right"> // this will align the column header
                    <af:outputText value="#{node.lineItem.amount}" id="ot8" inlineStyle="margin-right:15px;"/> // this will align column data
                  </af:column>

  • How can I right-align a table header?

    Does anyone know a way to right-align a table header?
    For example, in the table below I want the word 'Price' to be right-aligned. I could set the table's 'header renderer' to be a right-aligned DefaultTableCellRenderer, but then the header would look like a cell, not a header. Why can't swing be simple, like table.getColumn(1).setAlignment(Column.RIGHT) ????
    public class TestTableHeader {
         public static void main(String[] args) throws Exception {
              JFrame frame = new JFrame("Test");
              Object[][] rowData = new Object[][] { { "General Electric", "$100.60" },
                        { "IBM", "$5.20" }, { "Wal-mart", "$17.00" } };
              JTable table = new JTable(rowData, new Object[] { "Name", "Price" });
              DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
              renderer.setHorizontalAlignment(DefaultTableCellRenderer.RIGHT);
              table.getColumnModel().getColumn(1).setCellRenderer(renderer);
              frame.getContentPane().add(new JScrollPane(table));
              frame.setSize(400, 300);
              frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              frame.setVisible(true);
    }

    I modified your code an came up with a solution to the problem.
    import java.awt.Component;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.DefaultTableCellRenderer;
    public class TestTableHeader {     
         public static void main(String[] args) throws Exception {
              JFrame frame = new JFrame("Test");
              Object[][] rowData = new Object[][] {
                        { "General Electric", "$100.60" }, { "IBM", "$5.20" },
                        { "Wal-mart", "$17.00" } };
              JTable table = new JTable(rowData, new Object[] { "Name", "Price" });
              RightAlignRender right = new TestTableHeader().new RightAlignRender();
              table.getColumnModel().getColumn(0).setHeaderRenderer(right);
              table.getColumnModel().getColumn(1).setHeaderRenderer(right);
              frame.getContentPane().add(new JScrollPane(table));
              frame.setSize(400, 300);
              frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              frame.setVisible(true);
         public class RightAlignRender extends DefaultTableCellRenderer {
              public Component getTableCellRendererComponent(JTable table,
                        Object arg1, boolean arg2, boolean arg3, int arg4, int column) {
                   Component toReturn = table.getTableHeader().getDefaultRenderer().getTableCellRendererComponent(table,
                             arg1, arg2, arg3, arg4, column);
                   switch (column) {
                   case 0:
                        ((JLabel) toReturn).setHorizontalAlignment(DefaultTableCellRenderer.CENTER);
                        break;
                   case 1:
                        ((JLabel) toReturn).setHorizontalAlignment(DefaultTableCellRenderer.RIGHT);
                        break;
                   return toReturn;
    }

  • Right Align the Currency values in ALV report

    Hi Friends,
    I have developed a report and displayed the output using the ALV. I have columns for currency values in the output table.
    The fields for currency values are character fields. The values in the table for display, is properly right aligned (default for currency values). But in the output, the currency values are left aligned.
    Since I need blank lines in the output table after each entry, I have used the character fields in the output table so that I can clear them and append it to get the blank line.
    Please suggest me to get the currency values right aligned.
    Thanks in advance.

    try with this field in field catalog.
             just(1)        type c,        " (R)ight (L)eft (C)ent.
    for the currency field add this field too in field catalog. it will work.

  • How to right align a read only numeric field in a panel form layout

    Hi, does anyone know how to right align a read only numeric field in a panel form layout? I am using: Style Class = AFFieldNumberMarker, but it only seems to work if the field is disabled. Disabling the field gives it a difference appearance that does not look right on our forms. These are calculated fields, which cannot be modified, so read only is necessary.
    I have looked online for some answers, and it seems that others are having similar issues.
    I have tried different combinations for the properties, but so far I cannot get it to work.
    Thanks
    Judy
    I am using JDEV 11.1.1.5

    Sorry for the delay in my response. Here is the code
    <af:inputText value="#{bindings.TotalAirlineCostEst.inputValue}"
    label="#{bindings.TotalAirlineCostEst.hints.label}"
    required="#{bindings.TotalAirlineCostEst.hints.mandatory}"
    columns="#{bindings.TotalAirlineCostEst.hints.displayWidth}"
    maximumLength="#{bindings.TotalAirlineCostEst.hints.precision}"
    shortDesc="#{bindings.TotalAirlineCostEst.hints.tooltip}"
    id="it20" readOnly="false"
    disabled="true"
    styleClass="AFFieldNumberMarker">
    <f:validator binding="#{bindings.TotalAirlineCostEst.validator}"/>
    <af:convertNumber groupingUsed="true"
    pattern="#{bindings.TotalAirlineCostEst.format}"
    type="number"
    maxFractionDigits="0"/>
    </af:inputText>
    thank you,
    Judy

  • Is it possible to use tabs to right align text in Muse, as you can in InDesign?

    Can I use tabs to right align text in Muse, as you can in InDesign?
    I have a beauty treatment followed by a price and I want to right align the price, keeping the treatment on the left of the text box.
    Thank you!

    For what would typically be a two column tab stop layout, I'd generally use inline text frames and the Wrap panel.
    Put the price in it's own text frame. Then cut and paste the text frame BEFORE the item name so it's an inline text frame within the text frame containing the descriptions.Using the Wrap panel set it to float to the right. Then select it and set the right offset so it floats outside the right side of the original text frame.
    Start with this.
    Cut and paste the text frame at the start of the item paragraph.
    Choose the third icon in the Wrap panel to cause the item to float to the right of the text frame.
    Turn off the lock for the 4 wrap offset values.
    Adjust the right offset to a negative value so the item is outside the text frame to the right (to wherever you want it).
    Repeat the same steps above for the other items.
    Note that once it's set up this way you can freely edit the descriptions or change the width of the original text frame and the prices will adjust accordingly. This will also result in things lining up in the browser even if the text layout engine of a specific browser line breaks the text differently.
    This approach is tedious, but the end result will continue to line up as you make changes in Design view and will line up in every browser/OS/device.
    Someday Muse will support tables, which would be the more natural way to achieve this style of layout on the web. Until then, inline items with wrap is usually the best approach for this type of two column layout.

  • Need Number fields to be right aligned in ADF table.

    Hi All,
    I have af:outputtext in the column of ADF read only table and view attribute which is associated to this field is fetching numbers (type is Number). But by default in my page data (numbers) is displaying with left aligned.
    But my requirement is to display numbers to be right aligned. I tried by setting Horizontal property to 'right' (text-align = right), also tried by seeting Styledclass property to AFFieldNumberMarker / AFFieldNumber css properties. But still numbers are displaying with left aligned.
    Please tell me how to fix this issue?
    Thanks,
    Sadanand

    Hi,
    try attribute align="right" in af:column....
    Regards,
    Suganth.G

Maybe you are looking for