Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By KevinWorkman

Thread: How to have a default value in a textbox and its size not restricted

  1. #1
    prabhdsun is offline Member
    Join Date
    Dec 2012
    Posts
    22
    Rep Power
    0

    Default How to have a default value in a textbox and its size not restricted

    Hi there. the problem i am having is that i want a default value in a jtext field. Since i am starting out with a balance of $100 in the bank account, i want the JText field to be uneditable and to show $100 as my balance, which would then be updated later on based on if i withdraw money or not. here is my code
    Java Code:
    int balance = 100;
    this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    	balancePanel = new JPanel();
    	TitledBorder Titled6 = BorderFactory.createTitledBorder("Account Balance");
    	currentBalance = new JLabel("Current Balance");
    	TF5 = new JTextField("$ " + Integer.toString((int) balance));
        TF5.setEditable(false);
        balancePanel.setBorder(Titled6);
        balancePanel.add(currentBalance);
        balancePanel.add(TF5);
        add(balancePanel);
    When i run the Gui, the text field restricts around the 100 dollars, making it pretty small. is there a way it can show the balance and be a wide text field? What i am asking is, if instead of putting in the balance, i had put 12, it would be pretty wide, but when i put the balance, becomes small. so is there a way it can be 12 wide and show the balance?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default Re: How to have a default value in a textbox and its size not restricted

    Check out the JTextField api for useful functions. Hint: you're looking to set the minimum size, right?
    foulkelore likes this.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    prabhdsun is offline Member
    Join Date
    Dec 2012
    Posts
    22
    Rep Power
    0

    Default Re: How to have a default value in a textbox and its size not restricted

    yes im trying to set the minimum size as well as have the balance display in it, but i dont want the textfield to become small just to fit the balance.

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default Re: How to have a default value in a textbox and its size not restricted

    Quote Originally Posted by prabhdsun View Post
    yes im trying to set the minimum size as well as have the balance display in it, but i dont want the textfield to become small just to fit the balance.
    ...did you look at the API like I suggested?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    prabhdsun is offline Member
    Join Date
    Dec 2012
    Posts
    22
    Rep Power
    0

    Default Re: How to have a default value in a textbox and its size not restricted

    yes, i did, thank you very much for your help. i found it!!! just had to use setprefferedsize XD

Similar Threads

  1. What is the default heap size of a java program?
    By guest_user in forum New To Java
    Replies: 8
    Last Post: 07-16-2011, 10:20 AM
  2. Changing default Applet Viewer Size?
    By dsym@comcast.net in forum Java Applets
    Replies: 6
    Last Post: 08-27-2010, 06:42 PM
  3. Replies: 1
    Last Post: 03-10-2009, 01:12 PM
  4. Time restricted method
    By toby in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:54 AM
  5. Replies: 1
    Last Post: 07-14-2007, 05:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •