How to resize JTextArea when frame has been resized

Hi!
At first, I have to complain, that these Layout Managers drive me crazy. Even as an experienced developer, very often, I am frustrated and I am never 100% sure which layout manager I should choose (according to the Sun How Tos) and once I have decided, the never do what I'd expect them to do. I'm not sure if I am just too dumb or if there might be an unreasonable API architecture/design...
OK, here again is a problem with layouts. And it's basically like this (See code for details):
Row one: Text Area 1, Button 1; Row two: Text Area 2, Button 2.
I just want to have the buttons aligned, the text areas should be same sized. Moreover, I want to disable vertical resizing and on horizontal resizing, I want the TextArea to be resized as well.
But it doesn't. I could partly solve the vertical resizing by setting the minimum size, but the maximum size dosen't seem to work. I can still enlarge the window. The horizontal resizing doesn't work at all. I tried border layout before and set the Text area as center, but it also doesn't work. I read that some layout managers use only preferred size, some also use min and max size and this is very confusing.
And I saw that component resizing should work for box layout as well (see Sun box layout how to). If this problem is easy to solve, please excuse my question, but I couldn't find it in the forum.
OK, here is an SSCCE:
* To change this template, choose Tools | Templates
* and open the template in the editor.
package com.ettex.componentresizetest;
import java.awt.ComponentOrientation;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
* @author Jan Wedel
public class ComponentResizeTest extends JFrame{
     static ComponentResizeTest frame;
     JPanel mainPanel;
     JPanel firstPanel;
     JPanel secondPanel;
     JPanel statusPanel;
     JButton firstButton;
     JButton secondButton;
     JTextField firstField;
     JTextField secondField;
     JLabel statusText;
     public ComponentResizeTest(String name) {
          super(name);
     public void addComponentsToPane() {
          Container pane = this.getContentPane();
          mainPanel = new JPanel();
          firstPanel = new JPanel();
          secondPanel = new JPanel();
          statusPanel = new JPanel();
          pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
          firstField = new JTextField();
          secondField = new JTextField();
          statusText = new JLabel("Status Bar");
          firstField.setPreferredSize(new Dimension(500, 25));
          secondField.setPreferredSize(new Dimension(500, 25));
          secondButton = new JButton("A Button");
          firstButton = new JButton("Another Button");
          firstPanel.add(firstField);
          firstPanel.add(secondButton);
          firstPanel.setLayout(new BoxLayout(firstPanel, BoxLayout.X_AXIS));
          secondPanel.add(secondField);
          secondPanel.add(firstButton);
          secondPanel.setLayout(new BoxLayout(secondPanel, BoxLayout.X_AXIS));
          mainPanel.add(firstPanel);
          mainPanel.add(secondPanel);
          mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
          statusPanel.add(statusText);
          FlowLayout tabLayout = new FlowLayout();
          tabLayout.setAlignment(FlowLayout.LEFT);
          firstPanel.setLayout(tabLayout);
          firstPanel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
          secondPanel.setLayout(tabLayout);
          secondPanel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
          statusPanel.setLayout(tabLayout);
          statusPanel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
          pane.add(mainPanel);
          pane.add(statusPanel);
      * Create the GUI and show it.  For thread safety,
      * this method should be invoked from the
      * event dispatch thread.
     private static void createAndShowGUI() {
          //Create and set up the window.
          frame = new ComponentResizeTest("Component Resize Test");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          //Set up the content pane.
          frame.addComponentsToPane();
          /* Layout componets */
          frame.pack();
          /* Prevent vertical resize */
          Dimension cur = frame.getSize();
          Dimension max = frame.getMaximumSize();
          frame.setMinimumSize(new Dimension(cur.width, cur.height));
          frame.setMaximumSize(new Dimension(max.width, cur.height));
          frame.invalidate();
          /* show frame */
          frame.setVisible(true);
      * @param args the command line arguments
     public static void main(String[] args) {
          //Schedule a job for the event dispatchi thread:
          //creating and showing this application's GUI.
          javax.swing.SwingUtilities.invokeLater(new Runnable() {
               public void run() {
                    createAndShowGUI();
}Thanks, Jan
Edited by: stelzbock on Nov 9, 2009 6:54 AM

This is what I get using TableLayout:
The maximum horizontal size of the text area is achieved by specifying the columns in the constructor,
although I think it's bad since resizing smaller does reduce the text area. I would use FILL constraint for the text area column and remove the 'filler' column at the end.
import info.clearthought.layout.TableLayout;
import java.awt.EventQueue;
import javax.swing.*;
public class TestLayout {
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                TableLayout layout = new TableLayout(new double[][] {
                        // columns
                        { TableLayout.PREFERRED, TableLayout.PREFERRED,
                           TableLayout.FILL },
                        // rows
                        { TableLayout.PREFERRED, TableLayout.FILL,
                          TableLayout.PREFERRED, TableLayout.FILL },
                JPanel panel = new JPanel(layout);
                panel.add(new JScrollPane(new JTextArea(3, 30)), "0,0,0,1");
                panel.add(new JButton("One"), "1,0");
                panel.add(new JScrollPane(new JTextArea(3, 30)), "0,2,0,3");
                panel.add(new JButton("Two"), "1,2");
                JFrame frame = new JFrame("Test");
                frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                frame.getContentPane().add(panel);
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
}Ah, in your code you have text fields, not area and want to restrict vertical resize. Then I get this:
TableLayout layout = new TableLayout(new double[][] {
                        // columns
                        { TableLayout.FILL, TableLayout.PREFERRED },
                        // rows
                        { TableLayout.PREFERRED, TableLayout.PREFERRED,
                            TableLayout.FILL, TableLayout.PREFERRED },
                layout.setVGap(5);
                layout.setHGap(5);
                JPanel panel = new JPanel(layout);
                panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
                panel.add(new JTextField(30), "0,0");
                panel.add(new JButton("One"), "1,0");
                panel.add(new JTextField(30), "0,1");
                panel.add(new JButton("Two"), "1,1");
                panel.add(new JLabel("Status"), "0,3,1,3");Another more advanced layout to look at is MigLayout.
Edited by: WalterLaan on Nov 9, 2009 8:23 AM

Similar Messages

  • TS3276 How to get message when email has been received and read?

    How do I set my Mail so I can get a message when an email has been received and read?

    Read receipt feature is not available in Mail, unfortunately.
    Best.

  • HT1212 how will i know when ipad has been restored?

    I am trying to restore my ipad.  Itunes has finished downloading the update.  how will i know when the ipad has been restored?

    It has given me an error 3194 - this device is not eligible for the requested build.  What now?

  • If my iPad is lost, how do I know when it has been removed from my Apple ID account?

    I lost my son's iPad this afternoon. By the time I realized I couldn't find it and pulled out my phone to use the Find Phone My iPhone app, it may have been too late to set it up as lost. The iPad is still displaying in the app, but simply as offline. Of course, the iPad could be laying on the street somewhere, God only knows. However, if someone had reset the iPad and logged it into their own account, would it still display on my "Find My iPhone" account even if it were offline? Or, since they can reset it without being online, will it wait to refresh until they get it online? I am literally sick to my stomach, I just bought this 64 gig brand new mini two months ago for my autistic son, and he uses it daily. I cannot fathom the idea that it is not in the house, but if it were in the house, it would be connected to our Wifi automatically, and it would not be dead because I just charged it for him for our short trip today. How can I see if the seriel number is even still on my account? When I go into my account, it shows a white mini ipad, ours is black, and it does not show the same seriel number. HOWEVER, it does show that I called about the Mini on the 29th of October, so even though it is displaying as white with a randomly different seriel number, I did call about an issue on that device. Why would iTunes have a different mini seriel number set up under our account? If you cannot tell, I am freaking out. We're out $500 and I feel like there just has to be a way to get our iPad back. (Just for all of you KARMA beleivers out there: About a year and a few months ago, I was at the pool with my son and found a Kindle Fire. I immediately went through to find the owners information and contacted her to return it! There has to be good Karma for me in this situation!! ;-)  )   Please, help me determine if the iPad is still connected to my account! Anything! Thanks!

    I think you may need to book an appointment with a genius! They will fix it or replace it for you, for free!!! You can book an appointment at your local apple store at http://www.apple.com/retail
    Hope this helps
    Conchuir

  • TS2446 how to purchase things when account has been locked

    I curently tried to buy smething but have forgotten the answers to my security question..... how can i fix that or change it?

    There are ways around this, but we can't get into that here. You'll have to do it through the normal channels:
    Check the AppleCare number for your country here:
    http://support.apple.com/kb/HE57
    Call them up, and let them know you would like to be transferred to the Account Security Team.

  • How can i see when someone has accessed my call/text log. (This is possible on google) I have been informed that someone has accessed my activity log and is giving my information to a third party. I believe it is a service tech, but I am not interested in

    How can i see when someone has accessed my call/text log. (This is possible on google/gmail) I have been informed that someone has accessed my activity log and is giving my information to a third party. I believe it is a service tech, but I am not interested in persuing that further. I just need to see when my account has been accessed if possible.

    Hi lynniewigs,
    This is a common concern among Android and I-phone user, and one of the drawbacks to using a smart phone.  We lose so much privacy. Our phones become cameras into our homes for us to be spied on.
    I don't know what type of phone you have, if it is even a smart phone, but here is an example of an application that you can use to determine which applications are accessing your information and sending it out. 
    Permission Scanner - Android Apps on Google Play
    Google just recently revamp their permissions geared to hide invasive applications that spy and send out your information without your knowledge.  Report says be aware of what your Android app does - CNET
    Please continue to be mindful of the apps you download and the permissions you give. 

  • HT1212 How do i restore my iphone when it has been disabled and can not be restored through itunes because of the error message that says "The iphone software update server could not be contacted.

    How do i restore my iphone when it has been disabled and cannot be restored through itunes because of the error message that says "The iphone software update server could not be contacted

    Have you jailbroken this device? This will make the iPhone not talk to the Software Update Server (that signs and accepts software updates) please refer to the following link? Error 3194, Error 17, or "This device isn't eligible for the requested build"
    The iPhone will talk to the software update servers, just need to change the host files, it's a simple process, sorry if you were confused about the wording in to top?

  • How do I unlock my iPod touch when it has been disabled?

    How do I unlock my iPod touch when it has been disabled? My children can't remember the four digit pass code they entered and it is now disabled.

    Recovery mode...
    http://support.apple.com/kb/HT1808
    You may need to try this More than Once...
    Be sure to Follow ALL the Steps...
    But... if the Device has been Modified... this will Not necessarily work.

  • TS4036 How do I access content that has been backed up to iCloud?  I no longer have an iphone, but want to access the music/pictures I've stored to the cloud.  When I logged into iCloud, there was no tab or option to view store content.  Please help.

    How do I access content that has been backed up to iCloud?  I no longer have an iphone, but I want to access the music/pictures I've stored to the cloud.  When I logged in to iCloud, there was no tab or option to view content.  Please help.

    Without an iPhone or iPod Touch to restore the backup to, you cannot access the camera roll photos stored in the iCloud backup.  Signing into the account on your computer and enabling photo stream will only allow you to access photo stream photos from the last 30 days, and any shared stream you were subscribed to.
    You can redownload purchased music in iTunes on your computer as explained here: http://support.apple.com/kb/ht2519.

  • Error message: ni: A frame has been dropped and the acqusition has been canceled

    I use a NI PCIe 1433 framegrabber with a Basler spl4096-140km line camera.
    Using triggered acqusition with an external source, I can get a framerate of 68500Hz in NI-MAX.
    When I use the Matlab image acquisiton toolbox to acquire data, I however very often get the error message: 'ni: A frame has been dropped and the acqusition has been canceled". This happens even at much lower framerates (20kHz) and only seems to go away when acquiring data slowly.
    Computer is a Dell Precision 7600 and I assume there should be no issues with RAM or the PC being slow. The error does not go away when reducing the data size (i.e. reducing the ROI to one single point that is readout).
    Do you have any pointers why this error message appears and what can be done about it?
    Thank you!
    Reto

    Hello,
    I encountered the same problem and I think it is because the allowcation of storage in matlab cannot catch up with that of the camera so that it will drop frames when the buffer is full.
    I also want to know how to solve that.
    Yang

  • Keeping count of how many times a case structure has been entered.

    I have a "Case" structure (when a button is pressed, it is "case True").
    I want to keep track of how many times this "case True" has been entered.
    How can I do this?
    Solved!
    Go to Solution.

    For that you need to have a shift register or a feedback node and keep counting whenever the case structure case is executed the count will be increased by one see the attached snippet.
    Good Luck
    The best solution is the one you find it by yourself
    Attachments:
    CaseStructure count.png ‏10 KB

  • How to get PDF file that has been transformed into docx into my filing system so I can work on it???

    How can I get the PDF file that was transformed into a docx file into my filing system to be able to work on it and translate it as the customer requested?

    THanks for your reply.
    Well what happens is I bought the program. It gives you a button to click,
    you log in and then a box opens up asking you to select the file, I go into
    my filing system (in Windows explorer) select the file, and the program
    converts it into docx, my choice.  I can read it there and when I try to
    copy and paste it into my file where the PDF version is saved, it behaves
    like an "image", and I can't save it.... or it saves likes something you
    save on the internet, so you have to go into internet every time you want
    to see it.    I have also pressed any amount of buttons to see if it will
    give me the option to save it any other way, and have found nothing.  What
    I would need is a file in docx.format that I can edit.  People send me
    things in PDF and sometimes I can just copy it off the PDF file and save it
    in WOrd, then I can translate it for them. But sometimes the PDF file
    doesnt allow me to copy the text.  If it is in image form, I cannot work on
    it.  It means printing it, so I can copy type it into Word... and for that
    I certainly wouldnt need to buy a program.  Its just double the work and
    ends up that the job takes twice as long.!
    Sorry  if I am a bit dumb with informatics.  But I simply could not find
    any way whatever to  copy the PDF file that was transformed into Word, in a
    format that would enable me to edit it.
    Kindest regards,
    Margery
    2013/12/2 Test Screen Name <[email protected]>
        Re: How to get PDF file that has been transformed into docx into my
    filing system so I can work on it???
    created by Test Screen Name<http://forums.adobe.com/people/TestScreenName>in *Adobe
    ExportPDF* - View the full discussion<http://forums.adobe.com/message/5890871#5890871

  • How to know if a file has been updated in iCloud after modification?

    How to know if a file has been updated in iCloud after modification?
    I work on various app including Keynote on my Mac Pro. And after modification, i close file and I wait.
    When I see no more Internet traffic. I assume that keynote has uploaded all the works I have done into iCloud.
    But when I open the same file on my iPad on the way to work. I do not see the file updated.
    I assume that I did not wait long enough.
    I wished I had a way to enforce the updated file to upload and way to get confirmation that it has been completed.
    In windows I simply push the sync button.
    But for iCloud I do not yet see anything like that.
    Please help.

    you would be better served asking this in the iCloud discussion, where users are more knowledgeable about iCloud. Replies on iOS and iCloud issues are usually unanswered here because of our lack of knowledge.

  • Why is the message app popping up on my mac when everything has been disabled on my iphone and mac, I use my phone for messages, not my mac. Is this a bug? I just want it off my mac forever!

    Why is the message app popping up on my mac when everything has been disabled on my iphone and mac as per the instructions all over this forum, I use my phone for messages, not my mac. Is this a bug? I just want it off my mac forever!
    Have disabled in Messages > preferences on the Mac
    imessage is disabled on my iphone
    Same goes for Safari which pops up on the mac when I open it on my iphone, how can I disable it all?

    Thanks but have signed out, disabled and nothing.
    It's Yosemite not Mavericks.
    What it won't let me do is delete the account as the - button is greyed
    out.
    It won't let me delete the app from the OS
    On Monday, February 2, 2015, Apple Support Communities Updates <

  • Is it possible to block an ipod touch when it has been stolen ?

    Is it possible to block an ipod touch when it has been stolen ?

    - If you previously turned on FIndMyiPod and wifi is on and connected go to iCloud: Find My iPhone, sign in and go to FIndMyiPhone. If the iPod has been restored it will never show up.
    - You can also wipe/erase the iPod and have to iPod play a sound via iCloud.
    - Change the passwords for all accounts used on the iPod and report to police
    - There is no way to prevent someone from restoring the iPod (it erases it) using it.
    - Apple will do nothing
    Reporting a lost or stolen Apple product
    - iOS: How to find the serial number, IMEI, MEID, CDN, and ICCID number

Maybe you are looking for

  • Sound issues with MacBook Pro

    I am experiencing sound issues with my MacBook Pro. I am using a headset and when I am on a skype calsl I have a hard time hearing the other person, the sound is coming in and out and sounds digitized. This issue only started recently, the sound had

  • How do i get a song to repeat on new itunes update

    Since updating to the newest Itunes I have not been able to repeat songs. How do I do this through Itunes on my computer?

  • Build in lenovo camera

    2 problems with lenovo camera: 1- using the camera program of lenovo EASY CAPTURE- when i change camera to lower  resolution -it is not fixed and goes back to max. resolution. WHY? how to FIX it? 2- the camera is not recognized at  control panel->sca

  • Price in PO / Invoice.

    Hi all, I am trying to input my Material price in PO as U$12.5434. I encounter the below error:(in MIRO also). “Input should be in the format ___.___.__~,__”. Price is rounding with 2 decimals Eg- U$12.54 or 12.50. I would like to know: A) Is it SAP

  • How much would it cost to trade in my iPod touch 5g 32 gig for a new one that's the same just a different color?

    I got a red iPod touch 5g and I just feel like getting the black one which looks nicer