Centering Text in ouput?

I have an issue where i am trying to center output of priority que.
I am not sure how to call the centerformat in display PQ() to format the print statement?
Basically the output has to be like.
BR - Brown
SM - Smith
but centered in the middle of the screen?
class pq
public void displayPQ()
            linein =  queArray[1].getStateRgnNum() + queArray[1].getStateRgn());  
            System.out.println("Region " + queArray[1].getStateRgnNum() + ":" + queArray[1].getStateRgn());        //formating for display output
            System.out.println(" ");
            for(int j=0; j<queArray.length && queArray[j] != null; j++)       //goes through each Priority Queue and displays items
                System.out.println(queArray[j]);
                }//end of for loop
            System.out.println("");
            System.out.println("");
        }//end of displayArray()
class App
public void centerformat(String linein)
            String space = null;
            int spaces = (28 - linein.length())/2;
            for(int i = 0; i < spaces; i++)
                space = space + " ";
        }       

>
I am not sure how to call the centerformat in display PQ() to format the print statement?Create an instance of the App class in the displayPQ() method and invoke the centerformat() method from it.
Although, looking at your centerformat() method, it has some defects. More so: it isn't doing anything.

Similar Messages

  • Centered text in PDF

    Hi
    I am new to this Acrobat SDK forum. I am trying to write a PDF code, but I have problems centering text. Below is a short "program" that writes the text "Centered text" starting at position x=100, y=600. But how do I center this text at some position, say x=200, y=600 ?  Can anyone help?
    - gullipeX
    %PDF-1.4
    1 0 obj
       << /Type /Catalog
          /Outlines 2 0 R
          /Pages 3 0 R
       >>
    endobj
    2 0 obj
       << /Type /Outlines
          /Count 0
       >>
    endobj
    3 0 obj
       << /Type /Pages
          /Kids [ 4 0 R ]
          /Count 1
       >>
    endobj
    4 0 obj
       << /Type /Page
          /Parent 3 0 R
          /MediaBox [ 0 0 612 792 ]
          /Contents 5 0 R
          /Resources << /ProcSet 6 0 R
                      /Font << /F1 7 0 R >>
                      >>
       >>
    endobj
    5 0 obj
       << /Length 73 >>
    stream
    BT
       /F1 24 Tf
       100 600 Td
       ( Centered text ) Tj
    ET
    endstream
    endobj
    6 0 obj
       [ /PDF /Text ]
    endobj
    7 0 obj
       << /Type /Font
          /Subtype /Type1
          /Name /F1
          /BaseFont /Helvetica
          /Encoding /MacRomanEncoding
       >>
    endobj
    xref
    0 8
    0000000000 65535 f
    0000000009 00000 n
    0000000074 00000 n
    0000000120 00000 n
    0000000179 00000 n
    0000000364 00000 n
    0000000466 00000 n
    0000000496 00000 n
    trailer
       << /Size 8
          /Root 1 0 R
       >>
    startxref
    625
    %%EOF

    Hi, Irosenth and others again.
    To try to solve my problem (because I do not know how to do this in PDF), I made a short PostScript program to check the length of the characters in Helvetiva 10 pt. A part of the program is shown below. If I have the length, I can calculate the centered position of the text in my C or Fortran program, that makes the PDF file.  This investigation gave, for instance, the lengths for A, B and W as:
    A:  6.66797
    F:  6.10840
    W: 9.43945
    When I placed the EPS file into Adobe InDesign a bit different values came out:
    A:  6.66959
    F:  6.10963
    W: 9.43942
    ... and still different in Adobe Photoshop:
    A:  6.67081
    F:  6.11075
    W: 9.44115
    I have the feeling that character lengths are given as integers in the font file (not as real numbers) and I actually have to multiply these lengths (for 10 pt. Helvetica)  with some unknown value to find the "correct" lengths of the given characters. Does anyone know the actual length of the character A in Helvetica for instance?
    PostScript program:
    /Helvetica findfont
    dup length dict begin
      {1 index /FID ne {def} {pop pop} ifelse} forall
      /Encoding ISOLatin1Encoding def
      currentdict
    end
    /Helvetica-ANSI exch definefont pop
    gsave
    /str 20 string def
    /Helvetica-ANSI findfont 10 scalefont setfont
    (A ) 50  750 moveto show
    (A)  stringwidth pop str cvs  80 750 moveto show
    (F ) 50  700 moveto show
    (F)  stringwidth pop str cvs  80 700 moveto show
    (W ) 50  650 moveto show
    (W)  stringwidth pop str cvs  80 650 moveto show
    grestore

  • Smartforms centered text formatting

    Hi, i have a problem developing a smartform form, when i use centered text it should appear:
           Avenida das Forças Armadas, 111 2º C
                           1600-045 LISBOA
                    Nº Contribuinte xxxxxxxxx
    Tel. +351 21 xxx xx 00 - Fax +351 21 xxx xx xx
    In the MS WORD editting box it looks right, but when i print the form the output widens the spaces between words like this:
                         Avenida       das      Forças      Armadas,     111    2º    C
                                                     1600-045     LISBOA
                                             Nº    Contribuinte     xxxxxxxxx
    Tel.    +351     21     xxx     xx     00    -    Fax      +351      21     xxx      xx     xx
    Thank you for the help.
    Edited by: tiagoramalhais on Feb 24, 2011 8:10 PM

    The Print output depends on the paper Size ! Why don't you try using a Standard Text for your requirement ?

  • HTMLEditorKit Centering Text

    Hello,
    I am writing a basic html editor which uses a textPane and java's HTMLEditorKit. The program allows the html to be saved.
    At the moment the text can only be written in a row by row form. And I would like to add the option of centering text, and images Which could be switch on and off, suchas in Microsoft's word.
    Could anyone provide an example of how to achieve this, or over some guidance.
    Thank you

    Thanks,
    I had a look at the site, though I could not find the answer, to how to use the java tools StyleSheet HTMLDocument and HTMLEditorKit kit. And allow the user to center text and images within a textpane, which would add the center tag to the HTMLDocument which contains the html template.
    Could you possibly advice further?

  • How do I put two centered text in a PAGE_START in BorderLayout ?

    Hi everybody.
    I am using a BorderLayout and in PAGE_START section I want to put a title(centered, with two rows). I don't know how to do that. When I put my text there, is on the left side.
    Thanks.
    Edited by: blackblack13 on Jul 18, 2009 1:08 AM

    Aaa yes, you're right. The thing with two JLabels is very good, I didn't think about that. But with HTML I don't know how to use it. Where can I find smth about that?
    Thanks a lot !

  • How do I place a transparent image over specific, centered text?

    I'm helping someone with a site that flows sales copy down the center of the browser window. We want to take a transparent oval and place it over a price that will be in the copy. (It would look like someone took a marker and circled the price.)
    I had learned that AP Div could solve this problem and, to an extent, it does. I can place the oval right over the price. But it only works when the copy is left justified, not centered. If the copy is centered, I can place the oval, but if the browser window is resized, the oval stays in place while the copy is reflowed to the new browser window size. Thus the oval is no longer over the correct text.
    Then I learned that Layout Mode might solve this problem, however that has been removed from CS4.
    So now my question is how do I to take a transparent .png file and place it over copy on this site so that if the browser window is resized, the .png file stays with the correct text as the text is "moved" to stay in the center of the brower window?
    I want to avoid the workaround of simply creating a .png with the oval and the price and inserting that in the middle of the copy at the appropriate place. There must be a better way to handle this. Not being too familiar with Dreamweaver, maybe there's some sort of Anchor function similar to one in InDesign that solves this issue.
    I've attached the simple oval .png file we're trying to use for this.
    Thanks in advance for any help.

    How about having the circle underneath the text? I know it's a compromise, but it will be much easier to do as you can assign a background image to the div or table cell which holds the text.
    For example, make a blank graphic and create a class:
    .price
        background-image: url(nocircle.png);
    then assign it to the text and give each text div a unique name
    <div class="price" id="price1">10.99</div>
    then you can turn the background image on and off using Dreamweaver's javascript controls, for example:
    onclick="MM_changeProp('price1','','background-image','url(circle.png)','DIV');"
    Hope that helps.
    Peter

  • Problems centering text in an includes file.

    I am trying to create an includes file (footer.php) to be displayed in a template file (index.dwt.php).  Am having troubles trying to get it to center the text when it's drawn in and displayed in the templates page.  It always comes in left justified for some reason.  Any help would be appreciated. Thanks.
    Bob Green

    How are you doing the footer?
    If your CSS has a rule that will center text in the footer that is in a paragraph, then you must make your text file for your include have the HTML:
    If your css says:
    footer p {
         text-align: center;
    And your text file for the include is:
    <p>&copy; 2013 big business, inc., All Rights Reserved</p>
    Then the text should be centered. But if it doesn't have the opening and closing paragraph marks, then it won't.
    Simple things like that may cause peoblems for includes.

  • Numbered headers with centered text: the numbers are off to the side.

    Hi,
    I'm trying to create typical numbered headers as they appear in law reviews. For example, (I used underscore characters here to represent characters):
    ___________________III.Judge-made law
    However, Pages seems to only do this:
    III.___________________Judge-made law
    That is, the text is centered, but the number is always in the left margin. Is there anything I can do about this?
    Thanks!
    Message was edited by: pdxlatenite
    Message was edited by: pdxlatenite

    Well, I'm not trying to write to the left of the list; I want to change the list number/character's formatting/placement, especially when the list text is centered.
    It looks like this kind of header, a centered one, wasn't contemplated by the creators of the software.

  • Centered text in a circular textframe

    Hello all!
    Here is a mild gripe: A simple logo of 3 letters in a round textframe. Why is it so hard to type three letters in a round type frame, where the letters are centered horizontally and vertically and are sized to fill up the frame?
    Things I notice: 1. You can't center it vertically (with Text Frame Options). 2. It is off a bit horizontally. 3. You cannot come near the full area of the circular frame but that it will go off into overset hiding.
    So simple a need. So difficult to do. Why? What is your workaround? Yes, I'm serious!
    Mike Witherell in Alexandria, VA

    Excuse me but I like most the jmlevy idea/alternative:
    Center the text in a text frame and paste it inside the circle.
    First because is simple, logical and (more or less) intuitive, as it just places a text frame inside a circle.
    Step by step:
    Create a text frame and type the text.
    Center it horizontally (Shift+Cmd(Ctrl in WIndows)+C)
    Press Cmd/Ctrl+B to access the Frame Options, select vertical justification>Center, on the Baseline options tab, choose:Cap Height.
    Select and cut the text frame
    Draw the circle. (Click with the Ellipse Tool (L) or the equivalent frame tool on the page and type the dimensions).
    (With the circle selected) choose Edit> Paste Into.
    If it does not fall in the center:
    In the contextual menu (right mouse button): Fitting>Frame fitting options click the central point in the Align from proxy icon.

  • Centering text & wrapping words on lines

    Hi all,
    I need to have a JLabel that centers the text in it, and allows for multiple lines, where if a line is too long, it wraps onto the next line.
    I started off with a JTextArea, setting "setLineWrap" and "setWrapStyleWord", and this works fine for long lines of text. But, I need to have the text centered as well. Is there any way of doing this? I know JTextPane can do it, but I can't see how to do it in JTextArea.
    any help much appreciated,
    Justin

    Use a JLabel, with HTML text content and set the preferred size of the label as well. This will do auto line wrap;
    ie. ew JLabel("<html><center>The long text</center></html>");ICE

  • Centering text in a cell in a JTable

    Hi,
    I have a program that reads in data from a text file and display it in a JTable. My problem is that the data in each cell is not centered, it is left justified within that cell.
    How can I fix this.
    --kirk                                                                                                                                                                                                                                                                                                                                                                                                                                            

    To align a text inside a cell you have to go through the rendering classes of a Jtable. You can do lots of formatting by using a render class. Heres my code that i use.
    1. The first code aligns your data centered inside the cell.
    2. The second code aligns it like code1 but has an additional character to be printed beside your data inside the text.
    ///////////// TO USE THE RENDER CODE IN YOUR APPLICATION /////
    TableColumn col1 = table.getColumnModel().getColumn(1);
    col1.setCellRenderer( new SimpleRenderer());
    or
    TableColumn col1 = table.getColumnModel().getColumn(1);
    col1.setCellRenderer( new SimpleRenderer( "$" ));
    ///////////// RENDER CODE IS HERE //////////////
    import javax.swing.table.*;
    import javax.swing.border.*;
    import javax.swing.*;
    import java.awt.*;
    public class SimpleRenderer extends JLabel implements TableCellRenderer
         Border unselectedBorder = null;
         Border selectedBorder = null;
         String text = "";
         Color foreColor = Color.black;
         Color backColor = new java.awt.Color( 217,217,255 );
         Color selectedColor = new java.awt.Color( 217,217,255 );
         public SimpleRenderer()
         super();
         setHorizontalAlignment( JLabel.CENTER );
         setOpaque( true );
         } // end of CONSTRUCTOR
         public SimpleRenderer( Color foreGround, Color backGround )
         super();
         setHorizontalAlignment( JLabel.CENTER );
         setOpaque( true );
         this.foreColor = foreGround;
         this.backColor = backGround;
         } // end of CONSTRUCTOR
         public SimpleRenderer( String data )
         super();
         text = data;
         setHorizontalAlignment( JLabel.CENTER );
         setOpaque( true );
         } // end of CONSTRUCTOR
         public Component getTableCellRendererComponent(
              JTable table, Object object, boolean isSelected, boolean hasFocus,
                                                                                    int row, int column)
         try
              if ( backColor != null )
                   if ( (row % 2 ) == 1 )
                             setBackground( backColor );
                   else
                             setBackground( Color.white );
              if ( foreColor != null )
                   setForeground( foreColor );
              if ( hasFocus )
                   if ( isSelected )
                             setBackground( selectedColor );
                   else
                             setBackground( Color.white );
              String newData = "" + object;
              if ( newData.trim().equals( "" ))
                   setText( "" );
              else
                   setText( text + " " + object );
              if (isSelected)
              if (selectedBorder == null)
                   Border border, raisedBevel, loweredBevel;
                   raisedBevel = BorderFactory.createRaisedBevelBorder();
                   loweredBevel = BorderFactory.createLoweredBevelBorder();
                   Border colorLine = BorderFactory.createLineBorder(Color.red);
                   border = BorderFactory.createCompoundBorder( raisedBevel,loweredBevel);
                   selectedBorder = BorderFactory.createCompoundBorder( border, colorLine);
              setBorder(selectedBorder);
              else
              if (unselectedBorder == null)
                        unselectedBorder = BorderFactory.createMatteBorder(0,0,0,0,
                        table.getBackground());
              setBorder(unselectedBorder);
         catch( ClassCastException e )
         return this;
         } // end of GETTABLECELLRENDERERCOMPONENT method.
         public void setForeColor( Color data )
         foreColor = data;
         } // end of SETFORECOLOR method.
         public void setBackColor( Color data )
         backColor = data;
         } // end of SETBACKCOLOR method.
    } /** end of CLASS **/
    /////////////

  • Centering text vertically in text box

    When you open a text box how do you center the text in the middle from top to bottom(vertically), not left to right. The text starts immediately in the top left corner. I need it in the center of a predefined text box size, so that if you drew a line across the center of the box from left to right, the top half of the letters  would be above the line and the bottom half would be below the center line. In other words there should be the same distance above the words to the top edge of the text box, as to the bottom of the text box, from the center.

    Thanks for the reply. Let me start by saying I am definitely a newbie with Photoshop. So if you could explain what I should do in PS that would help. I'm using CS6 Extended. I really don't know the difference between Paragraph text and Point text, and not sure what you mean when you ask is this for an Action.
    I selected the "T" Horizontal type tool, and drew a box. Then I started typing. It looks like my selections are left align, center align, and right align. But it does not Center it in the middle of the box. The text is still at the top of the box. I have to have the box a certain size because of the project I'm working on. I'm assuming the text I'm selecting is what you are calling Paragraph Text. How do you use Point Text.
    It's basically the spine on a book cover. You place the Title and the Authors name there, but you have to make sure it fits within the spine width, and is centered in that area. Like if you were looking at the side of a book, the title/author should be centered along that spine from top to bottom.
    Thanks!

  • Centering Text Vertically

    By default, text sits on a line underneath the letters (the black line in the image).  I'm trying to make it so that the text is center along an imaginary line through the center of the text (the red line).   So that the 'dum' to the left
    of the 'B' will be centered within the height of the 'b' and not sitting along the bottom line.  Can this be done in Word 2010?
    Picture this text size 12 point that says 'dum' and the size 24 that reads' bT' and then again 12 point that says 'ext' to read
    dumBText. 
    The BT are large and should be the center point for the smaller text around it.
    EDIT:  I cannot embed an image or links so scratch the image part.

    You could insert ADVANCE fields before & after the BT to lower, then raise, the text position by 6pt. With field codes visible (Alt-F9 toggles them on/off), your string would look like:
    dum{ADVANCE \d 6}BT{ADVANCE \u 6}ext
    with the BT in 24pt. Depending on the font you use, you might need to change the 6 in each field, which is the number of points, to a different value to get the desired effect.
    Note: The field brace pairs (ie '{ }') for the fields are created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  • Centering text onto an image.

    How do you do it?
    For example
    g.drawImage(image, x, y, Graphics.HCENTER | Graphics.VCENTER);
    g.drawString("text", x, y, Graphics.HCENTER | Graphics.BOTTOM);does not work, I could try all different variations of positions; Top, Bottom, Vcenter, Hcenter for both graphics and text and the text still won't center onto the image, absolutely centered.
    Of course if Vcenter would work for text it'd probably do the job but that of course isn't allowed, in order for me to work around this at the moment I have to add a number to drawstring which looks like this.
    g.drawString("text", x, y+textAdjust, Graphics.HCENTER | Graphics.BOTTOM);Of course this is useless if ported onto another phone with a different screen size.
    Any help would be apreciated thanks.
    Edited by: GLGunblade on Jul 27, 2010 7:41 AM

    Though before I go changing every image in my code (It's a lot of images), is there no way to just alter text placement or does it have to be the background image to fit the text?Not sure what you mean here... What do you mean by changing every image?
    This simple calculation I have pasted in my previous post lets you position both text and image, so that their centers are aligned, which I think is what you want to achieve.
    All you have to do is to establish the height of the image and the height of the text every time you paint them, which is just a matter of calling some APIs.
    Daniel

  • Help centering text

    I'm trying to center a line of text in the text area.
    If the text entered can be displayed on one line, I would like the text centered; otherwise it should use the word wrap.
    I tried creating a method called center:
    // Defined outside this method, but shown since it is being referenced.
    int textAreaWidth = (int) textArea.getPreferredScrollableViewportSize().getWidth();     public String center(String text)
         int stringWidth = metrics.stringWidth(text);
         if (stringWidth > textAreaWidth)
              // Only handles text shorter than one line.
              return text;
         int availableWidth = textAreaWidth - stringWidth;
         int availableSpaces = availableWidth / metrics.charWidth(' ');
         int spacesToAdd = availableSpaces / 2;   
         // Adds the leading spaces to the text to center it.
         // Adds a trailing space as well to test the actual metrics length.
         for (int index = 0; index < spacesToAdd; index++)
              text = " " + text + " ";
         return text;
    }I coudln't find anything to use in the Java Doc, so I thought I'd write one to help me out.
    Testing it, I used:
    textArea.setText(center("m"));The issue is that the JTextArea is returning a width of 300. That is correctly set, and returning the right width.
    The string width is returning at 11, which is expected for the letter m.
    The available width is 289. Also correct. 300 - 11 = 289
    The metrics character width of a space is 3.
    The spacesToAdd returns at 48.
    A string with a metrics width of 299 is returned. That being, 48 spaces and the letter m.
    However, the JTextArea displayed in the JPanel shows this text wrapping onto a second line -- indicating the JTextArea displayed is not the actual width I set it to.
    The code to setup the JTextArea is as follows:
    JPanel panel = new JPanel();
    textArea = new JTextArea();
    textArea.setPreferredSize(new Dimension(300, 60));
    textArea.setLineWrap(true);
    textArea.setFocusable(false);
    textArea.setEditable(false);
    textArea.setWrapStyleWord(true);
    textArea.setFont(APP_FONT);
    scrollPane = new JScrollPane(textArea);
    scrollPane.setBorder(BorderFactory.createEmptyBorder());
    panel.add(scrollPane);What am I doing wrong?
    I suppose I could use a document and set styles... but ... I was trying to get this working...
    Help would be appreciated.. Thanks!

    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the posted code retains its original formatting.

Maybe you are looking for

  • Help on readubg .pdfs for Samsung SGH ZX20

    ...so I bought this beefed up phone, the Samsung SGH ZX20 with the 1Gg microSD card and USB transfer cable and see I may be S.O.L. on one of my desires to view .pdf files directly upon my phone. My question before I rant in another direction is: Can

  • Custom field data is lost or not available after any action

    I added a custom field on ERP_H component and I made this field available through getter methods. I brought this field in to header view and the field looks ok but after I enter the data in that field, the value enter doesn't get retained. I saw the

  • Warnings about root element must be well-formed

    Hey, I just downloaded and am getting running with FlexMetrics.  I'm running this from the ant taskdef.  When I run it, I get what looks to be valid and fine XML reports generated, but I also get a bunch of warnings, each of which reads: [flex-metric

  • Page not found problem

    I hope someone can help me with this mystery. I added a first level page to my site and checked it in preview mode. Looks great. Everything works fine. But when I published it, the menu bar takes me to a page not found error. So I saved the site as h

  • BUG: After refreshing 'Data Controls', I can no longer refresh 'Projects'

    If I add a new VO to the data model of my application module, I need to refresh the 'Data Controls' panel to see the new model object. To do this, I right-click on the data control in the Data Controls panel and click refresh. Once I have done this,