Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

jTextField resize issue

 
Greenhorn
Posts: 24
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sir When I need to resize jButton then I use preferredSize from property window.

But When I want to resize jTextField then preferredSize does not work.

The preferredSize of default jTextField is 57,19 but I want to increase it to 100,19
I replaced value  57,19 with 100,19 but no change.

https://imgur.com/a/W6hKKhj

How to resize jTextField without mouse or dragging it.
I want to use property window like to change jButton.

Please
 
Marshal
Posts: 72477
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't post that sort of link; people prefer to see the code here.
How are you setting the size for the text field? If I remember correctly, you suggest the number of characters you want it to accommodate.

Moving to our GUIs forum as this question seems to have nothing to do with NetBeans.
 
Tariqq Mehmoodd
Greenhorn
Posts: 24
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No sir, not number of characters, physical length (horizontal).

How do control it with property sheet.

Suppose my jTextField length is like this
----
----

How to make it more longer like this

-----------
-----------

But not with mouse.
 
Saloon Keeper
Posts: 23439
159
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The preferredSize is exactly what its name says: the preferred size. It is a suggestion, not a command, and while it will be taken into consideration when laying out a sub-view, it's only a suggestion and depending on the layout manager that's handling it, the preferred value may be ignored. You might actually have better results by setting the minimumSize, but that, too depends on the layout manager.

Also, don't forget that when you change the geometry of a view or sub-view, then you have to trigger a re-draw of the invalidated areas. Simply changing values only schedules them for the next rendering opration.
 
Rancher
Posts: 3232
30
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't use setPreferredSize().

Each Swing component is repsonible for determining its own preferred size.

When creating a JTextField you can use:



This will allow the text field to calculated is preferred size to display 10 "W" characters.

If you need more or less change the number.
 
Saloon Keeper
Posts: 4358
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a question about the NetBeans GUI Builder.

Well, dragging a JTextField into a JPanel, and then setting a preferred size in the properties window works for me. Did you check the settings for max size and min size (these are default Integer.MAX_INT and some very small numbers).

But GUI builders are designed to use drag and resize with the mouse. Why don't you want to use that?
 
Tim Holloway
Saloon Keeper
Posts: 23439
159
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piet Souris wrote:
But GUI builders are designed to use drag and resize with the mouse. Why don't you want to use that?



GUI Builders are not part of Java. They are provided by specific IDEs/IDE plugins. There was, in fact, a very long drought period between the demise of Borland's Visual Café and the GUI builder later added to IntelliJ, which triggered addition of GUI builders to competitive IDEs.

While I see that this question was cross-filed under NetBeans, all of the discussions have been about Swing itself, irrespective of the IDE used. And that's good because A) it doesn't encourage dependency on an IDE (the old IDE-as-a-crutch concern) and B) it means that answers are also of potential use to everyone, not just NetBeans users.

Plus, we don't get punished by screenshots.

Rob's suggestion is noteworthy. It makes a best-effort attempt to size the control specifically to its potential contents. The "W" character is typically one of the widest in a font, so it - or "M" - are often used at reference metrics for worst-case computation of the amount of real estate required to display entered text.
 
Piet Souris
Saloon Keeper
Posts: 4358
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
???

I really don't understand the relevance of your reply.
 
money grubbing section goes here:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic