JLabel moved when I type text

Using BoxLayout I have placed a JLabel on top of a JTextArea. Now, when I type text in the JTextArea, the JLabel moves.
Why does this happen, and what can I do to prevent it?
This is my code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class T2 {
    public static void main(String[] args) {
     try {
         javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
              public void run() {
               JFrame mainw = new JFrame("T2");
               mainw.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent e) {
                        System.exit(0);
               JComponent pane = (JComponent)mainw.getContentPane();
               pane.setLayout(new BoxLayout(pane,BoxLayout.Y_AXIS));
               pane.add(new JLabel("Write something here:"));
               pane.add(new JTextArea(10,30));
               mainw.setSize(200, 200);
               mainw.setVisible(true);
     catch (Exception e) {
         System.err.println("Exception: " + e);
}

Why does this happen, Read the Swing tutorial on [How to Use Box Layout|http://java.sun.com/docs/books/tutorial/uiswing/TOC.html]. It explains how components are aligned when the "X alignment" of compnents is different, which they are in your case (run the code below to see the output). So what is happening is the the label is being aligned to the center of the text area "preferred size" and the preferred size changes as you add text to it.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class T2 {
    public static void main(String[] args) {
     try {
         javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
              public void run() {
               JFrame mainw = new JFrame("T2");
               mainw.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent e) {
                        System.exit(0);
               JComponent pane = (JComponent)mainw.getContentPane();
               pane.setLayout(new BoxLayout(pane,BoxLayout.Y_AXIS));
               JLabel label = new JLabel("Write something here:");
               System.out.println(label.getAlignmentX());
               pane.add(label);
               JTextArea textArea = new JTextArea(10,30);
               System.out.println(textArea.getAlignmentX());
//               textArea.setAlignmentX(0.0f);
               pane.add(textArea);
               mainw.setSize(200, 200);
               mainw.setVisible(true);
     catch (Exception e) {
         System.err.println("Exception: " + e);
and what can I do to prevent it?Standardize the alignments:
textArea.setAlignmentX(0.0f);

Similar Messages

  • I have two different accounts on my iMac 2011 OSX 10.8.2. When you type text in one account, he dialed in the second account at a time. how to solve it?

    I have two different accounts on my iMac 2011 OCX 10.8.2. When you type text in one account, he dialed in the second account at a time. how to solve it?

    I have 2 users on the imac. when entering text in the first account it is duplicated in the second

  • When I type text numbers are randomly inserted into my text ?

    Suddenly my text generated in mail and MS word has random includes random numbers insert between the letters I have typrd.  Interestly when I tyor this post everything works fine ?? any suggestions ?

    Reset the device:
    Press and hold the Sleep/Wake button and the Home button together for at least ten seconds, until the Apple logo appears.
    If that doesn't help, tap Settings > General > Reset > Reset All Settings

  • Siri talking when I type text and email

    The Genius Bar did a reset on my phone in an effort to correct an issue.  After the reset (which did not solve my initial issue), Siri started trying to help me type my text and emails by speaking the words I am typing.  How do I shut her up without shutting her down?  Have had the phone for over a year and this did not happen until after the reset.  Thank you for your help. 

    Never mind.  After posting this question, I found the answer in "more like this."

  • How do I set up languages so when I type in English or Spanish my ipad 2 does not try to auto correct everything I type in spanish into English?

    I am trying to figure out how to set up my iPad so that when I type text or an email in Spanish, my iPad constantly changes everything into English.  I am a basic level user, so I need elementary level/ step by step instructions.  Thank you in advance.

    Go to Settings > General > Keyboard > International Keyboards. Add a new keyboard by pressing the Add a New Keyboard button. From the list choose Catalan.
    When you are typing using the keyboard you will see a world key. Tapping this key will loop through the keyboards you have set up. Choosing the Catalan keyboard will change the spelling correction to Spanish.

  • I am running Photoshop CC on a Windows 7 Toshiba PC and my text will not appear on the background when I type it.

    I am running Photoshop CC on a Toshiba laptop running Windows 7.  When ever I try to type text on a background image, the words don't appear.  NOW...I had been using it for two or three weeks with no problems whatsoever...but then about 5 days ago, it just quit working.  What I type shows up on a the layer pallet on a tab in the lower left corner of the screen, but it just won't show up on the graphic.  HELP!!!  I'm about ready to cancel my monthly subscription to Photoshop!!  I tried to reset my text "T" in the upper right corner, but I think I made things worse.
    Can I delete the program from my computer and REdownload it???  I've got things I've GOT to get done and I'm dead in the damn water and I can't seem to get any help.  I will tell you up front, I am NOT a computer genius, so any help will be GREATLY appreciated and if you could put it into step by step parts that would GREATLY help me.  I appreciate it.

    Thanks for the screenshot. You do not have to get rid of CC 2014.
    Open your Creative cloud panel, select Previous versions and 14.0 under Photoshop.

  • How to Print Text in the PLD when we select Type : Text

    Hi All
    I designed a PLD for Purchase Order which is working well but
    whenever we select type: Text and we enter some text in the row level for each item. when we see the PLD priview
    Items are displaying but the text below the items are not displaying
    it displays an empty row after each item
    How should i print text in the PLD
    I required in this following Format
    ITEMCODE  DESCRIPTION      QTY
    001              XYZ                      20
    this is capital Good Item
    002             PQR                        30 
    this is Raw Material
    In this above format
    I didnt get the text below the Items
    Can any one suggest the correct answer

    Thanks for your reply
    I already select the linetext field from table POR10 and kept it  in the PLD
    but i didnt get my required format
    after giving that line text field  iam getting
    in this way
    S.No.        ITEMCODE   DESCRIPTION  QTY
       1               001               XYZ                 20
    this is Capital Goods
      2                                                                 
    this is Capital Goods
    the text is repeating twice
    I Put the ItemDescription field  in POR1 and Line Text Field in POR10 in the same repetitve area

  • How to change the HTTP Response as XML (Content Type "text\xml")  When Post

    Hi Friends ,
    I have created one RFC Destination TYPE H . When i am trying to post some XML Message to that particular HTTP Service using POST method . It succesfully accepted the XML File but , it is returning the String as " OK" . In the connection test trace i have seen the Content Type as "text/html" but * I need to get as XML format no Srting    ( Type "text\xml" . ) *
    I need to get response back as XML not plain text .
    1 Any Configuration setting do we need to do on Service (SICF ) ?
    2. Or any other place we need to modify to get the HTTP Response as XML not plain text
    Can you please help to solve the problem . Any clue ?
    Thanks & Regards.,
    V.Rangarajan

    Dear users,
    we have requirement sending SMS to the customers mobiles. I am successfully sending the messages to the customers mobiles by using the above method. Facing issues with response message. The response messages is in plain text fromat in single line like...Sent
    Using HTTP_AAE Receiver adapter.
    The response message was failed while excution of the message mapping with the error
    Mapping failed in runtimeRuntime Exception when executing application mapping program com/sap/xi/tf/_MM_SMS_CUST_RES_; Details: com.sap.aii.utilxi.misc.api.BaseRuntimeException; Content is not allowed in prolog.
    please share the comments how to pass the Status of the message to SAP ECC from SAP HTTP adapter
    Regards,
    Sudir.

  • Messages has replaced all my text with a load of letter A's in boxes. What is that all about. When I type a new one it is fine until I hit enter then the same thing applies. Has anyone a fix for this?

    Messages has replaced all my text with a load of letter A's in boxes. What is that all about. When I type a new one it is fine until I hit enter then the same thing applies. Has anyone a fix for this?
    Picture below, many thanks for your help.
    Jason

    Back up all data before proceeding.
    Launch the Font Book application and validate all fonts. You must select the fonts in order to validate them. See the built-in help and this support article for instructions. If Font Book finds any issues, resolve them.
    Start up in safe mode to rebuild the font caches. Restart as usual and test.
    Note: If FileVault is enabled in OS X 10.9 or earlier, or if a firmware password is set, or if the startup volume is a software RAID, you can’t start in safe mode. In that case, ask for instructions.
    If you still have problems, then from the Font Book menu bar, select
              File ▹ Restore Standard Fonts...
    You'll be prompted to confirm, and then to enter your administrator login password.
    Also note that if you deactivate or remove any built-in fonts, for instance by using a third-party font manager, the system may become unstable.

  • I have created an editable PDF via Adobe Indesign. When I open the PDF in Adobe Acrobat Pro DC, is there a way to specify a font style? Or is there a way in InDesign to make sure when someone type in that text field it is a certain font?

    I need to make sure the text that is entered is a certain font to keep it continuous with the rest of the document. Thank you!

    To go into form editing mode, select "Prepare Form" in the right hand pane. You'll then get a toolbar along the top that contains the various form-related tools. The first thing to do is add a temporary button. You'll use this to determine the name of the font for use with the script as well as place the script that will change the font properties of the text fields. So create a button anywhere, double-click it to bring up the field properties dialog, and on the Actions tab add a JavaScript action to the Mouse Up event that is:
    // Mouse Up script for temporary button
    app.alert(event.target.textFont);
    On the Appearance tab, select the font that you want to use for the text fields. Once you've done that, close form editing mode and click the button. It will display a popup that will list the font name. This may be different than the name that appeared in the dropdown on the appearance tab, so write it down. For example, when I chose "Minion Pro" from the dropdown, the popup showed "MinionPro-Regular".
    The next step is to replace that Mouse Up script with the following:
    // Mouse Up script for temporary button
    // Change the font and font size for all text field in this document
    for (var i = 0; i < numFields; i++) {
        var f = getField(getNthFieldName(i));
        if (f.type === "text") {
            f.textFont = "MinionPro-Regular";
            f.textSize = 9;
    Replace "MinionPro-Regular" with the font name that you wrote down before and set the font size to whatever you want. Use 0 to specify a font size of "Auto".
    This script will change the font of all text fields to whatever you specify. When you've confirmed that the text fields are set up as you want, you can go ahead and delete or hide the button. If you think you'll be doing a lot of forms work, you can create custom tools in Acrobat to speed up this process, but this should get you started. InDesign won't let you specify a lot of field properties and actions, so you have to work this way, and using automation scripts is an accessible way to significantly speed up the process and avoid mistakes.

  • Firefox 4 does not validate REGEX in "pattern" attribute of INPUT (type = text) when diacritic characters are includes (Chrome does).

    Using HTML5 and Firefox 4.0.1, following code :
    <form>
    <input type="text" name="my_input"
    pattern="^[A-Z]([a-zA-Zçéèâêîôûäëïöü-]{1,47}|.)" />
    </form>
    fails to validate input like "François" or "André" but "Francois" ou "André" is accepted. The problèm occurs with string including any diacritic character.
    (The REGEX validates using "Expresso" Regular Expression Editor.)

    See https://developer.mozilla.org/en/HTML/element/input
    <blockquote>pattern HTML5:
    A regular expression that the control's value is checked against. The pattern must match the <u>entire</u> value, not just some subset. Use the title attribute to describe the pattern to help the user. This attribute applies when the value of the type attribute is text, search, tel, url or email; otherwise it is ignored.</blockquote>
    <pre><nowiki>pattern="^[A-Z]([a-zA-Zçéèâêîôûäëïöü-]{1,47}|.)$"</nowiki></pre>

  • When I type my text gets highlighted and then deleted.

    I am having a problem with typing. When I type fast my text gets highlighted and then deleted or typed over. Im not sure what is wrong. I think it is either a trackpad or keyboard. Any help be great!!

    The trackpad on the MB and MBP have a larger surface with more sensors than on previous laptops. As a result, when we type we have other fingers, thumbs etc. making contact with the trackpad and the trackpad receives input we don't intend. It happens to me quite often. So I hit Command + Z to undo and reposition the cursor. We need to train ourselves so that we keep our hands, palms, thumbs or other unnecessary body parts away from the trackpad while typing.
    cornelius

  • When i type my email, the text would go on and on and overflows. I mean to say it doesn't autmatically hit the right hand side wall and change to next line! I have to manually press enter and then next line starts. Started happening suddenly.pls help.

    When i type my email, the text would go on and on and overflows. I mean to say it doesn't autmatically hit the right hand side wall and change to next line! I have to manually press enter and then next line starts. Started happening suddenly.pls help.

    Does it happen when you reply to an email? If so, it might be that there's content in the original email (like an image or something similar) that overflows the window content, therefore the Mail app, when you hit the border, follows the content below instead of going on a new line. You might wanna try that.
    Also: Please do not post the whole question in the question title.

  • Keyboard shortcuts initiate when I'm trying to type text. (CS4)

    I will try to type text in certain places (such as to name a layer or group in the layers panel or type in a font name in the character panel) and instead of displaying characters, Photoshop will initiate it's keyboard shortcuts. For example, if I try to name a layer "bat", it will leave the layer name blank and it will highlight the brush tool, the selector tool, and then the type tool.
    I can type text on my document with the text tool and I can also type the document name in "Save" and "New".
    I'm not sure if I've accidently hit something on my keyboard that makes this happen, but I've never had this problem before.
    I ran the latest updates. I'm using CS4 on OSX 10.6.8.
    Any ideas?

    @PECourtejoie
    I can highlight the text field, for example, I can double-click a layer name and it will change into a field with a cursor and I can even highlight the current name. However, I did just discover that sometimes I can type a letter once and the following keystrokes will act like a shortcut (whether the same letter or a different one). I then have to place the cursor in another part of the word to make this happen again, but again, it only happens sometimes and for now it seems random.
    It will also occasionally delete nearby layers (maybe there's a shortcut that does that, but I'm not sure which keystroke I hit when that happens).
    My mouse didn't accidently click elsewhere, it's been consistent for an entire day now.
    I looked at my preferences and didn't see anything that would reset them (nor anything that would apply to this). Please let me know how and I will try it.

  • When I type I cannot add text when I select the text area and double click. Why?

    When I type I cannot add text when I select the text area and double click. Why?

    Premiere Elements 11  trial version for macMac computer photos uploaded to the timeline just finetrying to make a new title, streaming or in a framedouble clicked on the text in the box and nothing shows up when I type on my keyboard. I can delete the words that are there but not type in new ones. I selected the type and size, etc.
    Thanks if you can figure it out. I gave up!
    I may just un-install it all together if I can't get to work.Joanne
    Date: Thu, 9 May 2013 17:59:08 -0700
    From: [email protected]
    To: [email protected]
    Subject: When I type I cannot add text when I select the text area and double click. Why?
        Re: When I type I cannot add text when I select the text area and double click. Why?
        created by A.T. Romano in Premiere Elements - View the full discussion
    Joanne Murray J2 What version of Premiere Elements are you using and on what operating system (including 32 or 64 bit) is your Premiere Elements installed? Forgive the questions if you have been there and done that, but I do not want to take anything for granted that might hinder a speedy resolution to your issue. Are you opening an already created title that is sitting on the Timeline in order to edit it in the Titler or are you trying to create a new Title (Default Text or other)? Do you know how to work with the Selection Tool and Type Tool in the Titler? Once I know what version of Premiere Elements that you are using, I will give you specific how to details. Thanks. ATR
         Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/5307494#5307494
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/5307494#5307494
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/5307494#5307494. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Premiere Elements by email or at Adobe Community
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

Maybe you are looking for

  • Drill down reports (Reports 3.0)

    I am trying to create a series of drill down reports using Reports 3.0. To do this I have created buttons in each report which pass parameters to the next report using the srw.run_report package. I have a problem with the lowest level report where no

  • Payment being taken despite cancellation?

    Payment is still being taken (2 extra months) since I deleted Photoshop. I went onto "manage account" but it is not listed as an app, yet the money keeps coming out my account each month for Photoshop. Can anyone tell me how this can be cancelled and

  • Problem for re-install

    Hi, I'm on a macbook and when I use my OS X DVD to re-install, it re-boot and reboot again and again, etc... I can break the cycle by pressing "alt"  but I can't boot via my DVD. Please help... I've scan both disk and everything seems to be ok. Don't

  • Time machine taking days...

    Hello! New in this of mac computers. I got my Macbook air new version, and the time machine is taking forever (now it is saying around 19 days, and evolving from 10 MB to 10 MB every half an hour. The hard drive is a Lacie with USB 3.0, and not sure

  • Credit card charge

    recently i just registered my new credit to my psn account, and right after i registered my credit card. I got notification from the bank (since every transaction i done will be notified through sms from my bank) that sony charged me for sum amount o