Alignment of Text

I have a JList which show different attributes values of a item in a line.
I am trying to align each of the attributes to follow in the same vertical alignment. To do so, I used "\t"
but I am facing some problem, is that as the length of the attributes might varies (especially one of my attributes is a string which the length might varies drastically) so it doesn't work properly. In addition, each of the character has different width, is there any way we could find the total width of a string? Is there any other solutions?

Get the maximum width
public int CalculateWidth(Component component){
   FontMetrics fm;
   int width; 
   String label;
   fm = fComponent.getFontMetrics(component.getFont());
   width = 0;
   for(int i = 0; i < component.getModel().getSize(); i++) {
        label = (String)component.getModel().getElementAt(i);
        if (width> fm.stringWidth(label))
          width = fm.stringWidth(label);
   return width;
}

Similar Messages

  • How can I align a text object by the visible text and NOT by its bounding box?

    Illustrator CS4.
    I am trying to align some text to the center of the artboard. The bounding box is bigger than the text, so when I try to align it to the artboard it doesn't actually center align the artwork as I need it to. The text is needing to be aligned with another text object, so I can't just center align the text and then align to the artboard (which would eliminate the bounding box problem, I think). To make matters worse, the text I want to align has a stroke.
    The only way I know to currently align the text properly is to convert it to outlines. This is what I've done, but I need something better. I want to be able to have my illustrator file that has all editable text and then be able to make a separate identical file with all text converted to outlined paths. The only thing holding me back right now is that I can't get the exact alignment while everything is still as text.

    The solution is to simple to believe and probably why you over looked it.
    You make two text frames to exactly the height and width of the text. You position the text in the relative location and then group the text frames  then center that group on the artboard.
    Like such:
    If you ever want to add text that should be no problem but you have to re center.

  • Alignment of text in textField

    hi
    how to change the alignment of text when typing in textField ?

    I don't think JavaFX support right to left oriented languages like Arabic (I think support is scheduled for JavaFX 3.0).

  • How to align the text in justify format with SQL Server Reporting Services?

            How to align the text in justify format In SQL server Reporting Services? Is there any code to do so?

    Hi,
    I'm afraid that if you want to have this kind of functionality, you will need to write a custom control. Here is an example: http://msdn2.microsoft.com/en-us/library/ms345265.aspx. The issue with custom controls is that it needs to be known by all the reportservers that will render your report.
    Greetz,
    Geert
    Geert Verhoeven
    Consultant @ Ausy Belgium
    My Personal Blog

  • Verticle alignment of text

    Hi All,
    Is there any way to align the text vertically. At present the data seems to be aligned at the top, i need to align it in centre.
    I Tried Layout->Alignment->Align Centre (Vertically) but it has no effects.
    I also tried SRW.SET_JUSTIFICATION(SRW.JUST_HCENTRE) but it is for horizontal alignment.
    Please Help.
    Regards,
    Ashish Goel

    Hi,
    better u can use center justify. The text has come in to the report automatically center.
    See in the Report Layout model after B, I, U after that four options agiven start justify , center justify , right justify , flush justify
    . which justify u want u can select it .

  • Aligning the Text in Centre for MultiLine Cells in JTable

    Hi;
    Does anyone know how I could make a java table that has multiline text cells AND this multiline text is aligned to center? I tried to extend JTextArea and to implement TableRenderer - multiline was OK but it did not do anything on setHorizontalAlign. If I extend DefaultTableRender than I can align the text to center but I got no multiline...
    Any ideas?
    Kindly to provide me a solution for this its urgent.

    Hi;
    Thanks for the reply,on using Text Area as renderer i.e using Multi-Line cells in JTable, i achieved the objective of displaying the text on multiple lines in the cell."In my Table there are 5 columns and i'm setting renderer on 3rd and 5th column,If the text is too large in column 5 it automatically gets wrapped off for all the cells in column 5.For column 3 my text is not so large as compared to column 5 and due to which the Text in the column 3 starts from the top for all the cells i.e (the first row in column 3 is parallel to first row in column 5 ),Now the problem is i can't display the text in the center of all cells for Column 3 .
    Thanks in advance

  • JTable How to align the Text in a Cell to Centre

    Hi Plese Help regarding JTable.
    I want to align the Text in the Table Cell to Centre how to align it. Im using Abstract Data Model TAble an what is the meaning of renderer and its use.. Help me out

    Here are a couple of links you should read for information on tables and renderers:
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editrender
    http://www-106.ibm.com/developerworks/java/library/j-jtable/index.html?dwzone=java
    Here is an example of a simple renderer that will:
    a) center the text
    b) highlight the background when the cell gets focus
    This renderer is only used in two of the columns of the table.
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class TableRenderer extends JFrame
         public TableRenderer()
              String[] columnNames = {"Date", "String", "Integer1", "Integer2", "Boolean"};
              Object[][] data =
                   {new Date(), "A", new Integer(1), new Integer(5), new Boolean(true)},
                   {new Date(), "B", new Integer(2), new Integer(6), new Boolean(false)},
                   {new Date(), "C", new Integer(3), new Integer(7), new Boolean(true)},
                   {new Date(), "D", new Integer(4), new Integer(8), new Boolean(false)}
              DefaultTableModel model = new DefaultTableModel(data, columnNames);
              JTable table = new JTable( model )
                   //  Returning the Class of each column will allow different
                   //  renderers to be used based on Class
                   public Class getColumnClass(int column)
                        return getValueAt(0, column).getClass();
              JScrollPane scrollPane = new JScrollPane( table );
              getContentPane().add( scrollPane );
              //  Create cell renderer
              TableCellRenderer centerRenderer = new CenterRenderer();
              //  Use renderer on a specific column
              TableColumn column = table.getColumnModel().getColumn(3);
              column.setCellRenderer( centerRenderer );
              //  Use renderer on a specific Class
              table.setDefaultRenderer(String.class, centerRenderer);
         public static void main(String[] args)
              TableRenderer frame = new TableRenderer();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible(true);
         **  Center the text and highlight the focused cell
         class CenterRenderer extends DefaultTableCellRenderer
              public CenterRenderer()
                   setHorizontalAlignment( CENTER );
              public Component getTableCellRendererComponent(
                   JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
                   super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                   if (hasFocus)
                        setBackground( Color.cyan );
                   else if (isSelected)
                        setBackground( table.getSelectionBackground() );
                   else
                        setBackground( table.getBackground() );
                   return this;

  • Aligning a text layer to the centre of the image?

    Hi,
    I've just been creating a watermark for my photos in Photoshop CS5. I've found the 'Align' tool under 'Layer' in CS5 but align is greyed out. How can I align the text layer to the centre of the image if I can't use the align tool?
    Thank you!
    Chris.

    You need to select the layer (ctrl/a) then you can align it.

  • Centre align a text in a smartform

    Hello all,
    I want to centre align a text in a smartform. It is not using any paragraph format.
    I want to use formatting options like (C) for condense.
    thanks,
    Anju

    Hi Anju,
    In this case you have to create a paragraph format as CENTER center-aligned and use this paragraph format for the center alignment of the text.
    Nagaraj->
    Alignment can not be controlled using CHARACTER format.
    Regards
    DKS

  • Aligning dynamic text

    Hi,
    I've got a dynamic text box that retrieves text using Action
    script from an external PHP file. It works well except when I set
    the dynamic text in Flash to be centrally aligned it still aligns
    the text to the left when I play the movie. I'm guessing it's to do
    with the script I'm using to retrieve the PHP file but as I didn't
    write it myself I don't know what bit needs to be altered.
    Any help would be greatly appreciated,
    Leo (using Flash 8)

    Sorry, I misunderstood your question – the code was
    created in the authoring environment but despite assigned center
    alignment in the properties panel it didn't come out that way in
    the movie. Anyway I resolved the problem with the following piece
    of code...
    Cheers – Leo

  • How do you create aligned interactive text boxs in a PDF with the same width and height?

    how do you create aligned interactive text boxs in a PDF with the same width and height?
    Without free hand creating the sizing?

    Assuming by "interactive text boxes" you mean form fields; in Acrobat, make a form field, then copy it and paste. (GIve the pasted copy a different name so they don't genetate the same field feedback.) Now you have two fields of the exact same size. Shift-click or marquee-drag to select both, then right-click and choose a command from the Align, Distribute or Center menu.

  • Flahs CS3 Datagrid Dynamically align Header Text

    Hello!
    I am getting problem with Flash CS3 Datagrid. I am not able to align Header Text dynamically. Can any one sujest How to set Text Alignment dynamically. I want align first header column Text "left align" and rest of the columns Text are "right align".
    My code as bellow but it is not working
    .as code
    package {
        import fl.controls.dataGridClasses.HeaderRenderer;
        import flash.text.TextFormat;
        public class headerRender extends HeaderRenderer {
            public var headerTxt :TextFormat;
            public function headerRender()
                //this.super();       
                headerTxt = new TextFormat();
                headerTxt.font =  "Verdana";
                headerTxt.color = 0x000000;
                headerTxt.align = "right";
                headerTxt.size = 11;
                setStyle("textFormat", headerTxt);
    FLA code
    import fl.controls.DataGrid;
    import MyCellRenderer;
    import fl.data.DataProvider;
    import fl.managers.StyleManager
    import fl.controls.dataGridClasses.DataGridColumn;
    var dp:DataProvider = new DataProvider();
    dp.addItem({label:"Item a", data:0});
    dp.addItem({label:"Item b", data:1});
    dp.addItem({label:"Item c", data:2});
    dp.addItem({label:"Item d", data:3});
    dp.addItem({label:"Item e", data:4});
    dp.addItem({label:"Item f", data:5});
    dp.addItem({label:"Item g", data:6});
    dp.addItem({label:"Item h", data:7});
    dp.addItem({label:"Item i", data:8});
    dp.addItem({label:"Item j", data:9});
    var myDataGrid:DataGrid = new DataGrid();
    myDataGrid.addColumn("label");
    myDataGrid.addColumn("data");
    myDataGrid.dataProvider = dp;
    myDataGrid.width = 200;
    myDataGrid.rowCount = dp.length;
    myDataGrid.move(10, 10);
    addChild(myDataGrid);
    //set second header colum right align
    myDataGrid.getColumnAt(1).headerRenderer = headerRenders;
    Please let me know where I am wrong
    Mandar Mukadam
    Sr. Multimedia Developer

    This forum is about the Cloud as a delivery process, not about using individual programs
    If you start at the Forums Index https://forums.adobe.com/welcome
    You will be able to select a forum for the specific Adobe product(s) you use
    Click the "down arrow" symbol on the right (where it says All communities) to open the drop down list and scroll

  • Horizontal alignment for Text of Header Region

    Hi,
    The content of Text property for a header Region appears left aligned by default.
    Is it possible to set horizontal Alignment = Middle(of the Page)For the Item Type, Header I do not see any property called Horizontal Alignment in the Property Inspector.
    Thanks,
    Gowtam.

    Header component does not expose any property to align the text.
    Can you check whether, the following layout helps.
    TableLayout (Horizontal Alignment - center)
    |
    -- RowLayout (Horizontal Alignment - center)
    |
    --- CellFormat (Horizontal Alignment - center)
    |
    ---- Header

  • JLabel: How to Left Align the text

    Hi.
    I created a JLabel and wanted to left align the text. However, the text is always centered in the frame that contains it. Can you tell me what I need to add to the code?
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Frame.*;
    public class S extends JFrame
         public S()
              setSize(300, 300);
              setTitle("Title Bar");
              setResizable(false);          
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JLabel label = new JLabel("A label", JLabel.LEFT);
              label.setHorizontalAlignment(JLabel.LEFT);           
              label.setToolTipText("Should be left aligned");
              JPanel pane = new JPanel();          
              pane.add(label);
              setContentPane(pane);     
         public static void main(String[] args)
              S f = new S();
              f.show();     
    }Thanks
    Raja

    Read this section from the Swing tutorial on "Using Layout Managers":
    http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html
    Layout Managers layout the components based on rules for each layout manager.
    By default a JPanel uses a FlowLayout. By default FlowLayout aligns components in the center of the space allocated to it. In your case you allocated 300 to the width of the frame, therefore the panel has a width of 300, therefore the label is centered in the 300 pixels.

  • Text value not aligned with text caption

    Hello,
    In my text fields, the text value is always slightly raised from the text caption. Is there a way to get them to align?
    Thanks,
    Gail

    Hi Geo,
    I have tried top, middle, and bottom alignment and although they give different results, none are actually aligned with the caption text.
    The top and middle alignments still have the value text raised above the caption text.
    The bottom alignment gives a puzzling result of the value text being sunk below the caption text and actually somewhat cut off at the bottom.
    For some of my text boxes I have thrown together a work-around solution for this by setting the baseline shift for the value text to -3pt. Although this does seem to work, I don't imagine this is how the program was INTENDED to be used and I'd like to understand how to get the text aligned without having to tweak baselines.
    Any ideas or suggestions are welcome.
    Thanks,
    Gail

  • How do I center align the text in my text boxes if they are currently right aligned?

    I created a client questionnaire in Word and then turn it into a PDF and created the text boxes necessary. The problem I am having in Adobe XI Pro is that I want all of the text in my text boxes to be centrally aligned rather than left aligned. However, when creating and editing the text boxes, I see no option to help me do so. When clients fill out the form it looks messy because the information that the fill in tables in not centrally aligned, so it makes my tables look poorly organised. Help would be much appreciated, thank you.

    In Form Edit mode, right-click the field(s) and select Properties - Options, and under Alignment select "Center".

Maybe you are looking for