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...

Similar Messages

  • 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

  • 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 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;
    }

  • 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.

  • Right aligning one item in a VerticalLayout container?

    Hi All,
    I've got a container with a VerticalLayout.  I want all of the items to be left-aligned, except for the first one, which I want to be right-aligned.
    Is there a way to make that first item right-aligned?  If this were HTML I might put float:right on the item and make the following items clear:both, and that would do it.  But I'm not sure how to do it in Flex.  Can anyone give me some insight?
    Thanks!
      -Josh

    You can put it inside another container and right align that.

  • Mismatched Right-Alignment - Opera and Safari

    QUESTION:  What must I do to get Opera and Safari to behave like FireFox?
    BACKGROUND:   After several weeks of struggle I have finally taught myself to design a fully expandable horizontal SPRY menu bar in FireFox.  Although I am nearly able to obtain full expansion in Opera and Safari, my success is at best ephemeral.  Right alignment of my SPRY menu bar appears to vary with the width of my viewport.  Do I even dare look to see what is happening with Internet Explorer?
    In order to overcome this problem I have tried a myriad of options including negative right margin adjustments and positive left padding adjustments.  These have been applied to specially designated <div>, <ul>, <li>, and <a> tags.  Nothing appears to work.  This suggests that knowledge and experience at a level more advanced than my own is required.
    SOURCE PAGE:  http://homepage.mac.com/moogoonghwa/Imagine_Prototype/Content/
    Roddy

    QUESTION:  In the absence of margins, paddings, and borders what could be causing the separation of an image from the bottom border of its container?
    BACKGROUND:  In the page provided you will find a white separation between the bottom of the image and the document's footer.  This separation occurs in FireFox, Opera, and Safari.  I do not know what occurs in Internet Explorer.  The separation is not a part of the image, because I can change the color of the separation by simply changing the background color of the left-floated side-bar that contains the image.
    SOURCE PAGE:  http://homepage.mac.com/moogoonghwa/Imagine_Prototype/Content/
    Roddy

  • 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.

  • 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?

  • 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

  • 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

  • Issue with right aligning of Character Styles in my TOC

    Hello all!
    I'm working on my very first book project and I have been reading soooo many threads on here for the past hour, but i either just don't get it, or i didn't find what i needed still, so i already apologize in case this very question has been answered before ...
    ok, so ... i am building my TOC and have set up the corresponding TOC styles to the paragraph styles used throughout the book.
    what i want is for the page number to appear before the entry. so for the page number i have set up it's own TOC page number character style.
    NOW
    the page number appears left aligned. I have checked the character styles palette and there i can't set a tab for the page number to appear right aligned ...
    how do i get this page number to be right aligned? and THEN, how do i specify the distance between the page number and the entry? there is "tab character"mentioned on the TOC dialogue box to specify the distance between page number and entry, but then do i have to go in manually every time something changes? that can't be it? i have seen in the paragraphy styles palette there is a tab section ... tried to input the tabs so the number would appear right aligned and the distance to the entry, but nothing happened, then the number is stuck right on the entry once the TOC is generated ...
    does this make any sense?
    will attach a screenshot to try to clarify the issue ...
    hope you can help me out.
    thanks a lot in advance!
    cheers
    sta-cy

    sta-cy wrote:
    sorry to have bugged you.
    Seriously, if we didn't enjoy this stuff we wouln't be here. It's not like we even get T-shirts. :-P
    An awful lot of what I know and am able to pass on comes from having spent waaaaay to much time here reading about odd problems and trying to figure out ways to solve them. I'd never seen a requst like yours until the other day, but then up pops Joel with a similar story, and what do you know, this may not be such a strange thing to want at all. Hopefully your question, and the work we put into trying to find an answer, has not only helped you, but some other users who come along next week or next year.
    Everybody starts someplace and at some point in time. There's no shame in being a beginner, and less in asking for help when you need it, especially after you put in the effort you did on your own to try to find a solution. It's also true that some folks are more design oriented and others more process oriented, and that's just the way it is. This forum has many, many, followers who are expert in different areas of InDesign (even the engineers who write the program are not experts in all the various parts) and are here to share what they know as volunteers. You are always welcome here, especially when the question is as intersting as this one.

  • Problem with formatting text in textobjects with right aligned tabulators

    Post Author: Jens Kluesener
    CA Forum: General
    HiI want to print out some values in a line. So I put a Textobject in the Report with some right aligned tabulators (left aligned tabulators working fine). Then I insert a formula. In this formula i do this:"1"chr(9)"2"chr(9)"3"chr(9)"4"chr(9)"5"chr(9)"6"chr(9)"7"Look:            Many ThanksJens

    I think i found why.
    There was no problem with TextField.
    There was a problem with Array. "CityArea"
    So each time I executed script it added new string in Array. And that is because i got like:
    TextField
    City 1
    City 2
    City 1
    City 2
    Running this script is Ok:
    for (var i1:int = 0; i1 < CityArea.length; i1++)
      _CityAreaString1 += "<P ALIGN='LEFT'><FONT FACE='Verdana' SIZE='32' COLOR='#ffffff'>        "+CityArea[i1]+"</FONT></P>";
      _CityAreaString1 += "<P ALIGN='LEFT'><FONT FACE='Verdana' SIZE='5' COLOR='#ffffff'><BR></FONT></P>";
    But outside of this for loop there is another for loop for adding Cities in CityArray.
    I fixed it by adding empty array at the start of function
    function myFunc():void
    CityArea = [ ]; // Empty array fixed this issue
    // LOOP FOR ADDING SHOPS IN CITY AREA
    for (var j:int = 0; j < _Shops; j++)
    CityArea.push(_Shop);
    // FOR LOOP TO ADDING SHOPS IN STRING
    for (var i1:int = 0; i1 < CityArea.length; i1++)
      _CityAreaString1 += "<P ALIGN='LEFT'><FONT FACE='Verdana' SIZE='32' COLOR='#ffffff'>        "+CityArea[i1]+"</FONT></P>";
      _CityAreaString1 += "<P ALIGN='LEFT'><FONT FACE='Verdana' SIZE='5' COLOR='#ffffff'><BR></FONT></P>";
    Thank you for your help kglad

  • 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

  • XML Import is left aligning my right alignment style with an override, how do I force it to left?

    I'm importing an XML file, using the Import XML menu item, using InDesign CS4.
    In the document I've got a table, with an XML structure in the structure tree, matching in the incoming file. Everything works fine, except that after the 4 "template rows" that I've set up Indesign adds new rows automatically, and for all InDesign auto added rows, InDesign is not using the right alignment that I've set up in the paragraph style applied to the first rows... The style is kept, but overridden by a flush left. (Why?)
    How do I deal with this? I need the right column to go on right aligning
    Best regards, Andreas

    Map tags to styles took care of the problem.

Maybe you are looking for

  • Error occurred in deployment step 'Activate Features'

    I have created an Empty SharePoint Project in Visual Studio 2010 and added a Web Part. The scope for my feature is set to "Site". My "Active deployment configuration" is set to Default. When I click Deploy in the context menu of the project in Visual

  • How do I delete photos PERMANENTLY?

    I have moved photos to the trash can and emptied the trash can multiple times and they keep popping back up in Iphoto. Not just Iphoto but many other files are not actually being deleted. Plus, I'm finding random snapshots of my family's phone number

  • FAGLL03 - Line item display in ECC 6.0

    Hi We are on ECC 6.0.  When i execute the report FAGLL03 for Line item display and double click on a line, system pops up a window with Line item details rather than actually taking me to Document display for that Line item What settings do i need to

  • Help with d/l'ing video to the ipod

    ok ... i'm a noob at this ipod video thingy ... so can someone plz give me a detailed procedure to put videos onto the ipod??? plzzzz

  • N85_WLAN_connection_issue .. plz help

    Hi there.. I have a Speed Touch(585-vi) witch supports wireless connection. But i can not use my N85 for the internet through WLAN!! WLAN wizard recognize the access point thin connected. and when i use the browser i get this annoying message !!? WEP