Aligning Text in Center of JOptionPane

Hi,
I am trying to display messages using JOptionPane and a JDialog.
    JOptionPane pane = new JOptionPane(message,
                                       message_type,
                                       option_type,
                                       icon,
                                       options,
                                       initial_value){
      public int getMaxCharactersPerLineCount() { return    default_characters_per_line; }
    JDialog dialog = pane.createDialog(parent_component, title);
    dialog.setVisible(true);I want to be able to control the number of characters per line which I have found how to do, and to control the alignment of the text. I have not being able to work out how to control the alignment of the text. I would like to be able have the text centered so a long line followed by a short line is displayed nicely.
I have tried using <html><center>My Text</center></html>, however, 1stly the html tags are counted as character therefore shortening the 1st line and secondly is the message is over several line then the tag are broken up and not interpreted properly.
Any assistance greatly appreciated.
Leon

//Create the dialog.
                    final JDialog dialog = new JDialog(frame,
                                                       "A Non-Modal Dialog");
                    //Add contents to it. It must have a close button,
                    //since some L&Fs (notably Java/Metal) don't provide one
                    //in the window decorations for dialogs.
                    JLabel label = new JLabel("<html><p align=center>"
                        + "This is a non-modal dialog.<br>"
                        + "You can have one or more of these up<br>"
                        + "and still use the main window.");
                    label.setHorizontalAlignment(JLabel.CENTER);
                    Font font = label.getFont();
                    label.setFont(label.getFont().deriveFont(font.PLAIN,
                                                             14.0f));extract from
http://java.sun.com/docs/books/tutorial/uiswing/examples/components/DialogDemoProject/src/components/CustomDialog.java

Similar Messages

  • Aligning Text in Center of JTextArea

    This is a part of my previous question.
    Is there a way of aligning text, left-center-right in the JTextArea.
    Someone had mentioned JTextPane for aligning Text in the center. What is the code for this?
    Thanks again for your help.

    I'm sorry. I am new at Java so some of these concepts that may be clear to you aren't as obvious to me.
    I inserted the code as you instructed. However, I am not sure if I have to include something else.
    Please advise:
    import javax.swing.*;
    public class HelloClassTwoLine
    public static void main(String args[])
    JTextArea outputTextArea = new JTextArea(); //Create listbox object
    JScrollPane scroll= new JScrollPane(outputTextArea); //create vertical scroll object
    ===> added to original code JTextField textField=new JTextField();
    ===> added to original code textField.setHorizontalAlignment(textField.CENTER);
    outputTextArea.setText("Hello, This is Java 374\n" + //set text in list box
    "This is Java 374 with Ravi");
    JOptionPane.showMessageDialog(null, scroll, //text is argument in JScrollPane object
    "Java Program #2", JOptionPane.INFORMATION_MESSAGE);
    System.exit(0);
    thank you again for your help
    }

  • How to align text(left, right or center) on a button?

    I can not figure out how to align text on a button,
    could someone help me out?
    Thanks in advance

    JButton btn=new JButton("hi");
    btn.setHorizontalAlignment(int i)
    i=0 center
    i=2 left
    i=4 right

  • Problem with center aligned text when publishing

    Can anyone help me with this? I'm a bit desperate.
    I created blocks of text and center aligned them:
    Everything looked great but when I published all the text appeared left aligned.
    I tried everything but nothing seems to resolve this.
    Thank you in advance!
    Best regards,
    Paulo Moura

    Hi,
    Try exporting your file with the following settings to get a high quality GIF
    Dimensions   : Match movie
    Playback       : Animated
                        : Loop continuously
    Options         : Optimize colors
                        : Smooth
    Transparent   : Opaque
    Dither           : None
    Palette Type : Adaptive
    Max colors   : 99999
    Thanks!
    ps: please mark this post as Answered if this of any help to you

  • Problems Aligning Text in Headers and Footers

    I have tried to add headers and footers to documents and the  alignment is wrong.  The center footer/header should be center-aligned  and the right header/footer should be right-aligned.  Unfortunately,  they are both left-aligned.
    The preview shows the headers and footers aligned correctly, but when  the headers/footers are inserted in the document, the alignment reverts  to left aligned, although it is centered and on the right side of the  page, as appropriate.
    This is not a problem in Acrobat 7.
    Please advise if this is a bug and is awaiting an update, or if there is  something that I need to do to fix this problem.
    This is a screen shot of the preview windowindicating the proper alignment as indicated in the ovals:
    Here is the actual document once the header and footer are added.  Notice how the alignment switches to flush left:
    Any guidance is appreciated.
    Thanks.
    - James

    Nope.  The good folks at Adobe have neither addressed this issue (and I have
    heard from others that it is a problem for them as well) nor have they been
    very good about maintaining my account to be able to log in and follow up on
    it.
    The truth of the matter is that it appears to be a glitch in some, but not
    all, versions of this product and clearly it is not a big enough problem for
    them to want to fix it.
    I wind up using Acrobat 7 when I need properly formatted headers and footers
    or ‹ and this ought to get the attention of the folks at Adobe and maybe
    prompt someone (anyone!) to take a look and fix this glitch ‹ you should
    check out PDFPen.  It does much of what Adobe can do including headers and
    footers.
    If I didn't already have Acrobat 7 (and 8 and now 9), I would ditch Acrobat
    and just use Preview or PDFPen.
    - James
    From:  superfluities1 <[email protected]>
    Reply-To:  <[email protected]>
    Date:  Tue, 04 Jan 2011 12:11:19 -0700
    To:  "James A. Sarna, Esq." <[email protected]>
    Subject:  Problems Aligning Text in Headers and Footers
    Anybody ever solve this problem? I just started using(trying too, that is)
    Acrobat Pro for writing letters and starting at the top I ran right into
    this problem. Seems like a deal killer.

  • Cannot Align text in cell

    Greetings,
    I am having issues when trying to format my spreadsheet.  First of all, I have "Wrap Text in Cell" option turned on.  So when I have text that can fit into the cell, its fine.  But when I have long text in the cell, it wraps the text in the cell so it can fit inside, which I'm fine with.... but for some reason, it is not aligning it in the cell properly, so now part of the text it cut off.  I try to center align the text, but no use. I hit the button for "Align text in the middle of the table cell", and still does not align the text so that its centered, not cut off. I have included an image of what im talking about. Help please?

    Hello
    Here is what I get with Times New Roman under 10.6.8
    May you try to
    quit Pages
    trash the preferences file :
    <startupVolume>:Users:<yourAccount>:Library:Preferences:com.apple.iWork.Pages.pl ist
    restart Pages
    It it changes nothing, try to :
    quit Pages
    trash the preferences file :
    <startupVolume>:Users:<yourAccount>:Library:Caches:com.apple.iWork.fonts
    restart Pages
    Yvan KOENIG (VALLAURIS, France) mercredi 24 août 2011 21:24:52
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.0
    My iDisk is : <http://public.me.com/koenigyvan>
    Please : Search for questions similar to your own before submitting them to the community
    To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !

  • Align text in a textarea

    Greetings,
    Could anyone point me out in how to align a text in a textarea?, as in left/right/center ?
    Thank you

    An easy way to do it is to use a JEditorPane... here's an example class:
    package com.clearlyhazy;
    import javax.swing.*;
    import java.awt.*;
    public class AlignableTextPane extends JEditorPane {
         private static String LEFT = "\"LEFT\"";
         private static String CENTER = "\"CENTER\"";
         private static String RIGHT = "\"RIGHT\"";
         private String alignString = LEFT;
         private String realText;
         public AlignableTextPane() {
              super("text/html", "");
         public AlignableTextPane(String align) {
              super("text/html", "");
              setAlignment(align);
         public void setAlignment(String align) {
              if (align.equals(AlignableTextPane.LEFT) || align.equals(AlignableTextPane.CENTER) || align.equals(AlignableTextPane.RIGHT)) {
                   alignString = align;
         public String getText() {
              return realText;
         public void setText(String t) {
              realText = t;
              super.setText("<P ALIGN=" + alignString + ">" + realText + "</P>");
         public void setText(String t, String alignment) {
              alignString = alignment;
              setText(t);
         public static void main(String[] args) {
              JFrame tester = new JFrame("Alignment Test");
              JPanel mainPanel = new JPanel();
              mainPanel.setLayout(new GridLayout(1, 0));
              AlignableTextPane leftPane = new AlignableTextPane(AlignableTextPane.LEFT);
              leftPane.setText("This text is left-aligned.");
              mainPanel.add(leftPane);
              AlignableTextPane centerPane = new AlignableTextPane(AlignableTextPane.CENTER);
              centerPane.setText("This text is center-aligned.");
              mainPanel.add(centerPane);
              AlignableTextPane rightPane = new AlignableTextPane(AlignableTextPane.RIGHT);
              rightPane.setText("This text is right-aligned.");
              mainPanel.add(rightPane);
              tester.setContentPane(mainPanel);
              tester.setSize(400, 400);
              tester.setLocationRelativeTo(null);
              tester.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              tester.setVisible(true);
    }

  • Aligning text in JLabel

    Hi all,
    I'm simply trying to align text in a JLabel.
    I've been trying to use HTML formatting inside the JLabel, e.g:
    label = new JLabel (" <HTML><CENTER><P>Line one</P> <P>Line two</P></CENTER> </HTML>" );but when I try to use the <CENTER> tag it seems to be ignored?
    Why?
    How do I get around this?
    Many thanks.

    You can use the following code segment:
    JLabel ab = new JLabel("GG" ,  SwingConstants.CENTER);Hope it helps.
    --DM                                                                                                                                                                                                                                                                       

  • Aligning text in a button?

    I have a button (a simple rectangle) and I create a new layer and place text on the first keyframe while in Button Symbol Edit Mode. I now want to align the text in the center of the button. I drag over both the text and the button to select them both and than I open the Align Panel and I choose to align in the center. However, it is not aligning the text in the center and it is also moving the button to the left.
    What is the correct way to do this?
    Thanks.

    Sorry for not getting this. I'm coming from Illustrator, and there I can select the background shape and text, select the shape as a key object and align the text both vertically and horizontally inside the shape.
    I can not align the text vertically in the shape in FL. If I have both the shape and text selected, do I work with the align panel or the property inspector to do this?
    Thank you for your patience.

  • How to right align text in JTextArea

    Can u plz tell me how to right align text in JTextArea

    what do you mean by align text in java you mean you have a default text that align in the center is it?
    can you please explain ur question clearly
    Thanks

  • Left-aligning text in Final Cut 7

    I am using Final Cut Pro Version 7.0.3, doing mostly subtitles for TV series.
    Because of the amount of titles done daily, and because we left-align around 30% of all our subtitle text, I would save a lot of time if there was a keyboard shortcut to left-align text in the subtitle clips.
    Text Settings under the Control tab in the Viewer, automatically chooses Center Alignment, which is fine, but how can I left-align text without having to choose from the Alignment options? I could not find this option in the keyboard layout, so I could not assign a key for left-alignment.
    Does anyone know how to do this?

    This is not a direct answer to your question, but in my experience most FCP-7 users don't use the Text option in text intensive projects. As you have discovered, the Text options are limited.
    Instead they use Boris Title 3D which is bundled in FCP-7:
    Boris Title 3D gives you much more control over your text, and defaults to left justification:
    You might take a look and see if using this tool (which Apple provided to address the shortcomings of the Text generator) can help you.
    MtD

  • Vertically align text

    Hi
    Is it possible to vertically align text within a frame?
    Thanks

    Wade_Zimmerman wrote:
    I really do not think there is a reason to do this but if the OP has a good reason or wants to tell us why they need this we might be abe tooffer them a better way.
    I searched for a solution to this myself and missed this thread before i posted my own thread. but I find it odd how when this is asked for people are asked to give a good reason to use the bounding box, or like here told that there is no reason to need this. Well here is my current situation.
    I have a project that has 500+ peices. I am using data sets and variables.xml  to create them all quickly.
    Each one consists of a 1 of  three logos and 1 of 500+ lines of text and all the lines of text are  different lengths
    Now the problem I am having is getting the  text to wrap properly instead of running off the art board. This was easilly solved by using a text box. Now I am faced with a new issue, One line texts are all sitting really high on the artwork.
    So I would like to center all text vertically inside the box

  • How can I align text in Acrobat 8.1 Professional?

    Okay this is quite silly, but seriously how can I align text in adobe acrobat? I could not find a way other than creating a new document file which allows me to use alignment options automatically (example below), however does not allow me that when I reopen the same file (alignment and text options just dissapear on the bars, funny). Help anyone please? =/
    http://img152.imageshack.us/my.php?image=examplemo2.jpg

    Not that silly; but you ideally shouldn't be trying. Although there are some rudimentary (and sometimes unpredictable) editing tools in Acrobat, (I presume you are trying with the TouchUp Object tool as well as the TouchUp Text ?) much better to get it right in the source application and think of the pdf as what it basically is...a print.
    For whatever reason, v5 could edit text positioning rather more easily than the later versions.

  • How to align text at the top and bottom of a cell?

    I'm making a periodic table and need help with aligning text at the top and bottom of a cell. I'll have a picture in the middle of the cell with text above and below the pic. Thank you in advance for any kind of suggestions you can give me.

    It sounds as though you want to have 3 separate items inside of a single cell; text at the top of the cell, text at the bottom of the cell, and then a picture in the middle of the cell.  I am no expert, but to my knowledge that is not possible (someone please correct me if I am wrong.)  I also cannot figure out how to put a picture inside of a cell itself.
    I do have a way to accomplish the end result so long as what you need is the final look and not a useable table in numbers.
    Create 2-3 cells for each element.  (The middle cell, unless you can put pictures in a cell and I don't know, would just be there for peace of mind, but would hold the picture if you can, I would just do two if the pictures are to be in front of the cell anyway.)  The top cell align text to top on the Text tab of the inspector.  The bottom cell, align text to bottom on the same tab.  Then place the picture in the middle.  Now, you have what you want except there is one or two lines dividing the cells.  To get rid of this, either click the middle cell if you have one, or the top or bottom cell.  Click on the Cell tab of the inspector.  Select the bottom border and/or top border button and select "No Border" under border styles.  To make this fast, select a full row at a time, or use command click to select all of the same type of rows (middle, top, or bottom) and change all cells at once.
    I hope this helps.  Best of luck!
    ~Bret

  • How to align text to another text box

    I am very new to Indesign and I am signed up to Lynda.com so watching few a lot of tutorials, that said I need help with aligning text.
    I have a text box that is 100mm across. It has text centered. "£5"
    then above this I have in a smaller font saying "from"
    from
    £5
    I need to get the "f" of from to line up with the beginning of the £ sign? So that If I change the price to £500 the from sticks to the "£" Sign.
    To explain again the from needs to align to the left of the centred text.?
    Hope that make sense?
    Matt

    This can be done by putting the "from" text into a custom positioned anchored object just before the £ sign. You'll need to set the X coordinate relative to the anchor, and adjust the offset on both x and y to get the positioning where you want it.
    I'm sure there are lessons on Anchored Objects on Lynda.com.

Maybe you are looking for