JTextField - Setting the column size doesn't work. Help, please.

Hi,
I want to set the column size of a text field from another text field by the input from the user. However, it just doesn't work. The following is my code. Just check out the last anonymous inner class action listener. Somehow i can get the user text, but it just doesn't work.
Thanks for any helpful inputs.
* Introduction to Java Programming: Comprehensive, 6th Ed.
* Excercise 15.11 - Demonstrating JTextField properties, dynamically.
* @Kaka Kaka
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
public class Ex15_11 extends JFrame{
    // Create two text fields and three radio buttons
    private JTextField jtfUserText = new JTextField(10);
    private JTextField jtfColumnSize = new JTextField(new Integer(10));
    private JRadioButton jrbLeft = new JRadioButton("Left");
    private JRadioButton jrbCenter = new JRadioButton("Center");
    private JRadioButton jrbRight = new JRadioButton("Right");
    public static void main(String[] args){
        Ex15_11 frame = new Ex15_11();
        frame.pack();
        frame.setTitle("Excercise 15.11 - Text Field Property");
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    // Start of Constructor
    public Ex15_11(){
        // Set the the frame layout
        setLayout(new BorderLayout(5, 5));
        // Create three panels and two labels
        JPanel jpText = new JPanel();
        JPanel jpHorizontalAlignment = new JPanel();
        JPanel jpColumn = new JPanel();
        JLabel jlblTextField = new JLabel("Text Field");
        JLabel jlblColumn = new JLabel("Column Size");
        // Create a button group for the radio buttons to be grouped
        ButtonGroup group = new ButtonGroup();
        // Group the radio buttons
        group.add(jrbLeft);
        group.add(jrbCenter);
        group.add(jrbRight);
        // set a titled border for a panel
        jpHorizontalAlignment.setBorder(new TitledBorder("Horizontal Alignment"));
        // Create a line border
        Border lineBorder = new LineBorder(Color.BLACK, 1);
        // the all the components to their corresponding panels
        jpText.add(jlblTextField);
        jpText.add(jtfUserText);
        jpHorizontalAlignment.add(jrbLeft);
        jpHorizontalAlignment.add(jrbCenter);
        jpHorizontalAlignment.add(jrbRight);
        jpColumn.setBorder(lineBorder);
        jpColumn.add(jlblColumn);
        jpColumn.add(jtfColumnSize);
        // add the panels to the frame
        add(jpText, BorderLayout.NORTH);
        add(jpHorizontalAlignment, BorderLayout.WEST);
        add(jpColumn, BorderLayout.EAST);
        jrbLeft.addActionListener(new ActionListener(){
            // Handle event
            public void actionPerformed(ActionEvent e) {
                jtfUserText.setHorizontalAlignment(SwingConstants.LEFT);
        jrbCenter.addActionListener(new ActionListener(){
            // Handle event
            public void actionPerformed(ActionEvent e) {
                jtfUserText.setHorizontalAlignment(SwingConstants.CENTER);
        jrbRight.addActionListener(new ActionListener(){
            // Handle event
            public void actionPerformed(ActionEvent e) {
                jtfUserText.setHorizontalAlignment(SwingConstants.RIGHT);
        // Register the listener for the coloum size
        jtfColumnSize.addActionListener(new ActionListener(){
            // Handle event
            public void actionPerformed(ActionEvent e) {
                System.out.println(Integer.parseInt(jtfColumnSize.getText()));
                jtfUserText.setColumns(Integer.parseInt(jtfColumnSize.getText()));
}Edited by: ChangBroot on Dec 16, 2008 6:13 PM

don't forget to revalidate the JPanel after changing the components it holds:
    jtfColumnSize.addActionListener(new ActionListener()
      // Handle event
      public void actionPerformed(ActionEvent e)
        System.out.println(Integer.parseInt(jtfColumnSize.getText()));
        jtfUserText.setColumns(Integer.parseInt(jtfColumnSize.getText()));
        jpText.revalidate();
    });This will tell the jpText JPanel's layout manager to relayout the components that this JPanel holds. It should resize your JTextField. Note that in order to call this from within the anonymous inner ActionListener jpText will need to be declared "final". Either that or declared as a class field.

Similar Messages

  • I have iphone 4s and just bought an ebook for ibook, trouble is the font is so tiny I can't read it and the font sizer is not working? Please help!

    Hi, I have the  iphone 4s and just bought an ebook for ibook, trouble is the font is so tiny I can't read it and the font sizer is not working? Please help!

    Hello Glittergirl68,
    Thank you for using Apple Support Communities.
    It sounds like the function to reseize the Font in an iBook is not functioning properly.
    I recommend a few things here. First close all the apps that are running in the background:
    Double-click the Home button.
    Swipe left or right until you have located the app you wish to close.
    Swipe the app up to close it.
    From: iOS: Force an app to close
              http://support.apple.com/kb/ht5137
    When you have done that, restart the phone, and try again.
    If the issue persists, I would follow these steps from the article:
    iOS: Troubleshooting apps purchased from the App Store
    http://support.apple.com/kb/TS1702
    2. Check for app updates
    You can setup apps to update automatically in Settings > iTunes & App Store, but make sure that your apps are up to date:
    Open the App Store and tap Updates. If updates are available, tap Update All.
    If  prompted, enter your iTunes Store account information. App Store will then download and install the app updates.
    Note: Some apps may require a Wi-Fi connection to update.
    3. Install another app from the App Store
    If none of your user-installed apps will launch, there could be an issue with Apple ID authorization. Download and install an app that isn't already installed on your device to reset this information. You can also remove an app from your iOS device and download it again from the App Store or sync the app from your computer.Note: If you have installed apps using multiple Apple ID accounts, you may need to perform this step for each account.
    4. Restart the app
    If the issue affects only a single app, try closing just that app.
    5. Restart your device
    Turn the device off and on.
    6. Reinstall the affected app
    Remove the app from your device and reinstall it:
    Tap and hold any app icon on the Home Screen until the icons start to wiggle and show a small "x" in the top-right corner of the app.
    Tap the "x" in the corner of the app you want to delete.
    Tap Delete to remove the app and all of its data from your device.
    Press the Home button.
    Go to the App Store.
    Search for the app and then download it again.
    All the very best,
    Sterling

  • [Acrobat X Standard] The tool box doesn't work. Please help!

    [Acrobat X Standard] The tool box doesn't work. Please help!
    I have a Acrobat X Standard.
    When I open the documents, I can't click the tool box. but when I don't open the documents, I can use the tool box.
    To solve the problem,
    1. reinstall the menu.
    2. reboot the computer.
    But, It still didn't work.
    Plz help!!

    Was it AA X Std that you had these options in (sorry, I only have Pro)? If it was the trial (that is Pro), it may be that Std does not have to feature. Under XI at the Adobe site, there is a comparison of features between Std and Pro that might give you a hint.
    There is also an option to turn on or hide many tools. For me there is a small icon just above the tools...comment titles. If you select that it give a list of tools you can display. Often, several are not displayed by default. How you lost them is another things, but it is getting them that is the basic question.

  • Stuck on apple logo and Home button doesn't work, help please?

    Well, I dropped my iPod Touch 4g by accident and since that day, the home button hasn't really been working that well. Its very hard to use since you have to press it in really hard to get it to work and sometimes it doesn't even work at all. Anways, I was skyping with my girl and I didn't notice that I had to charge the iPod and it died on me so I was like what ever its normal and started to charge it. When it turned on, it got stuck on the Apple logo and its been there for more than a day now? What can I do? I know about the Press Home + Sleep button together but the Home button doesn't work at all anymore. I tried everything really. I tried to connect it to itunes and see if I could restore it but it won't recognize it no matter where I connect it. Tried it on 3 different computers and none worked at all.  I can't take it to an Apple store since there isn't any close to where I live and I really don't have anyone to take me there. So is there any other solution to fix my problem at home? or is it messed up completely? Someone please help me

    I have this same issue. But also, it isn't just that the lock/home button stops working, all buttons stop working. Even if you switch it to silent sounds are still played. I just got my iphone Thursday. Went to school the next day and pulled it out, it happened while it was locked I guess because my screen was black and I couldn't do anything! Thought it died already! This was around 12. Finally I pulled it out of my pocket again at around 3 and it showed the Apple logo and acted like it had just started back up. Which is what always happens after I get stuck playing a game or something. Help please, has happened two or three times just today.

  • How to set the column size in OATable

    Hi All,
    I'm using Oracle EBS 11.5.10
    I have a OATable with two columns (messagestyledText), say Col01 and Col02.
    Is there a way that I can set the width of Col01 and Col02 ? As in 30% of OATable for Col01 and 70% for col02?
    Thanks for any suggestion/help,
    Elmer

    Hi All,
    Got the answer. How I wish this can be define declaratively.
    Code below for the soln.
    OATableBean table01 = (OATableBean)webBean.findChildRecursive("table01RN");
    table01.queryData(pageContext, true);
    table01.prepareForRendering(pageContext);
    DataObjectList aColFormat01 = table01.getColumnFormats() ;
    oracle.cabo.ui.data.DictionaryData ColFormat01 =(oracle.cabo.ui.data.DictionaryData)aColFormat01.getItem(pageContext.findChildIndex(table01, "ColLabel"));
    //Column Width
    ColFormat01.put(WIDTH_KEY, "30%");
    //Column Format - Right-aligned varchar
    ColFormat01.put(COLUMN_DATA_FORMAT_KEY,NUMBER_FORMAT);cheers,
    Elmer
    Edited by: Elmer on Mar 8, 2010 2:46 AM

  • The menu button doesn't work! Please help me!

    I own a really cute ipod mini and i love it. But I had some trouble lately...the latest problem: my menu button doesn't work. well, i did everything i could do...reset all setting etc etc. but the problem still persists. Please help me!
      Windows XP  

    I own a really cute ipod mini and i love it. But I
    had some trouble lately...the latest problem: my menu
    button doesn't work. well, i did everything i could
    do...reset all setting etc etc. but the problem still
    persists. Please help me!
      Windows XP  
    same thing is happening to mine. i own a silver mini and recently it has been acting skrewy. the backlight goes on and off (without holding MENU and when the setting is at OFF) and the menu button doesnt work too. just today i discovered that when i do the HOLD switch it replaces the MENU process or ability.
    PLEASE HELP!

  • Since updating to firefox 9 my scroll feature on my touch pad doesn't work - help, please and thank you!

    since updating to firefox 09 my scroll feature on my touch pad doesn't work. How do I fix this, please? I have a Gateway laptop. This has never happened before with other updates.
    Thanks so much!!

    Thank you so much for your link - unfortunately it is totally beyond my skills to understand or correct the bug as posted. I can find the touchpad icon and right click to open the options and that's about my speed. If this is a bug should I uninstall Firefox 9? Thanks so much...

  • How can we set the column size and height dynamically

    Hi All,
    I have a requirement where i am designing rtf for excel output.Here i have a column where the height of that particular column must get reset dynamically according to the data that's getting populated.
    Thankq in advance.

    I had the same problem and I finally found that you can't set a form bean.
    There is no methods to do this.
    The only way is to make it a dynamic form bean, but i haven't investigated it.
    Now I use normal beans to move data between pages.
    Sorry if it's not what you want. If you have another solution let me know.

  • When I type in web searches, Firefox remembers them with a system similar to predictive text. How can I erase the search history list, because deleting the history with the organise tool doesn't work. Please help.

    When I type in searches I don't want a box to appear under the search box trying to predict what I'm going to type next. Can I disable the system(prediction box) or erase the history list or both?

    Thanks for the suggestion, but no effect, when I right click on the search bar all I get is; select all (which does nothing), add keyword to this search (which is the opposite of what I want) and add dictionary (again adding something). Do you have any other ideas? :)

  • 30 gb ipod 5th gen- Video doesn't work Help Please!!!

    I bought a used ipod off ebay, and ive been having nothing but problems with it. It came with music already loaded on it, but i deleted that music off. Then, I tried putting more music on it, and after successfully putting the music on it and ejecting the ipod, when trying to play the music on the ipod, it was blank. I restored it a million times, and I have the most recent update. Thankfully, I tried clicking and dragging the music from my library to the ipod and that worked. Now music is able to be played. But then, I tried putting videos on the same way. It was successfull, but when I tried to play the videos, the screen just goes blank, and after about 5 seconds it goes back to the menu. Ive tried switching the tv on and tv ask options to tv off, but that did not help, so if anyone can please help, it would be very much appreciated.

    Shaunie015 wrote:
    I may have dropped it one too many times
    I don't know what's wrong with it.
    You answered your own question.  If you do not want to take it to an Apple Store or an AASP for repairs, check too see if there are any solutions on the iPod Repair Tutorials website. 

  • Lion: lost admin p/w - resetpassword doesn't work help please

    Hi,
    I have a MBP running Lion. I have forgotten the password for the admin account.
    I have followed instructions to use cmd-r and then terminal and resetpassword. This brings up a window that seems to be just what I need, but when I reboot the new password is still not recognised.
    Can someone tell me why this isn't working and what to do to get it to work? Or another way to change the admin password?
    Many thanks
    <Edited By Host>

    Try one more time.
    http://reviews.cnet.com/8301-13727_7-20087723-263/how-to-run-the-password-reset- utility-in-os-x-10.7-lion/
    Best.

  • IPad 2 Doesn't work, Help Please?

    I just got my iPad2 for one day, now it stopped working with full battary. Tried connecting it to iTunes but iTunes couldn't access it.
    iTunes kept saying: " iTunes could not connect to the iPad because an invalid response was recieved from the device. "
    please help.

    now***

  • My itunes doesn't work, help please!!

    it doesnt want to sychronise....://

    That's too bad.
    When help is desired, provided specifics of the issue occurring.

  • Itunes says i need to upgrade, when i try it doesn,t work. help please

    i plugged my ihpone in to my comp amd it sai that i needed to uninstall and reinstll itunes 64 bit, now itunes won't open says error.
    any ideas please?
    thanks

    Have you had a chance to look at this troubleshooting page? If not, have a look at the bottom section that covers what to try if the message keeps reappearing: iTunes has detected an iPod in recovery mode - Use iTunes to restore
    Towards the end it says "If after restoring your iPod, the message described above reappears, the iPod drive letter may need to be reassigned. See the "Change the Drive Letter" section of this document for steps to assign a different drive letter" which contains a link to this article: Windows confuses iPod with network drive

  • I have just downloaded a £55 app but it doesn't work, help please???

    I have just downloaded an app but when I open it It just comes up with a white screen. I have no idea how or where to go to try and reinstal it, at £55 I do not want to have to re-pay for it, can somebody help me please.

    Hi..
    Helps to tell us which app you downloaded ...
    You can try re downloading. You will not be charged again.
    How to re download apps from the Mac App Store:
    Open the App Store. From the menu bar click Store > Sign In
    Click Purchases from the top of the App Store window.
    Select which apps you want to re download. Then right or control click where you see Installed  then click Install.
    Make sure and use the same Apple ID used for the original purchase.
    If that didn't help, if you have anti virus software installed, disable that.
    Turn off the Firewall in System Preferences > Security & Privacy
    If you have an app called Little Snitch installed, that can prevent apps from downloading.

Maybe you are looking for

  • How to find out the volume of the data updated in the custom table

    Hi, I need to find out the the volume of the data inserted or updated in the the custom table(Y tables).I have tried by the sm37.the job running in to update the table but i didnot get thde amount of the data.and if get the volume of the data which b

  • Setting the sticky bit on a file fails in a zone

    On initial inspection, the sticky bit on directories seem to be consistent across both the Global zone and local zone. However, they are inconsistent for files. Is this a bug, and if it is how to I raise a defect report? Excerpt from chmod man page:

  • 5.1 over analgue not working, 5.1 over digital work

    I have the 24 bit external li've sound card plugged into my laptop via usb. Well i connected it into my reciever via digital coax and i can get DD. But if i connect it via analogue wires(http://www.radioshack.com/product/in...entPage=search) i can on

  • How to upload normal excell file to ztable

    Hi All there, Can anybody tell me how to upload normal excell file to ztable directly. pl provide detail coding Regards Sagar

  • Search feature in the new 1.2 software not working

    i just watched the video of the announcing of the new ipod features and it showed him using a search feature from the new 1.2 software but i dont have it on my ipod. why is this?