Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Preferred Size, Minimum Size, Size

Reply
Thread Tools

Preferred Size, Minimum Size, Size

 
 
Jason Cavett
Guest
Posts: n/a
 
      05-23-2008
I'm a little confused when I should use the various JComponent
methods: setPreferredSize, setMinimumSize and setSize. From what I
can tell:

setPreferredSize(Dimension) - This is (obviously) the preferred size
of the component. As far as I can tell, this is used to determine
what size the component should be when pack() is used.

setMinimumSize - The component cannot be any smaller than this.

setSize - Set the current size (hard value).


What I'm confused about is...
1. When I should use each method.
2. Currently, when I resize a frame, the JTextBoxes will resize for
part of the time and then, as the JFrame gets smaller, they will
collapse to an extremely small size (1 character wide...if that). Do
I *have* to use setMinimumSize to prevent this from happening?/


Thanks for any info. Appreciate it.
 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      05-23-2008
Jason Cavett wrote:
> I'm a little confused when I should use the various JComponent
> methods: setPreferredSize, setMinimumSize and setSize. From what I
> can tell:
>
> setPreferredSize(Dimension) - This is (obviously) the preferred size
> of the component. As far as I can tell, this is used to determine
> what size the component should be when pack() is used.
>
> setMinimumSize - The component cannot be any smaller than this.
>
> setSize - Set the current size (hard value).
>
>
> What I'm confused about is...
> 1. When I should use each method.
> 2. Currently, when I resize a frame, the JTextBoxes will resize for
> part of the time and then, as the JFrame gets smaller, they will
> collapse to an extremely small size (1 character wide...if that). Do
> I *have* to use setMinimumSize to prevent this from happening?/
>
>
> Thanks for any info. Appreciate it.


The answer is it depends a lot on the layout manager that you are using.

The collapsing into a one pixel size makes me think that you are using
GridBagLayout. GridBagLayout can be configured to pay attention to
preferred and minimum size. I just tried it with my GridBagLayout
Tester JApplet and it appears not to honor maximum size.

So assuming you are using GridBagLayout the answer is yes you have to
set the minimum size. But remember if you shrink the container beyond
that which will hold the components at minimum size, they will disappear.

Feel free to play with my GridBagLayout Tester JApplet

http://rabbitbrush.frazmtn.com/gridbagtester.html

--

Knute Johnson
email s/knute/nospam/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      05-23-2008
On Fri, 23 May 2008 08:34:50 -0700 (PDT), Jason Cavett
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone
who said :

>setPreferredSize(Dimension)


see http://mindprod.com/jgloss/getpreferredsize.html
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
Jason Cavett
Guest
Posts: n/a
 
      05-23-2008
On May 23, 1:22*pm, Knute Johnson <(E-Mail Removed)>
wrote:
> Jason Cavett wrote:
> > I'm a little confused when I should use the various JComponent
> > methods: setPreferredSize, setMinimumSize and setSize. *From what I
> > can tell:

>
> > setPreferredSize(Dimension) - This is (obviously) the preferred size
> > of the component. *As far as I can tell, this is used to determine
> > what size the component should be when pack() is used.

>
> > setMinimumSize - The component cannot be any smaller than this.

>
> > setSize - Set the current size (hard value).

>
> > What I'm confused about is...
> > 1. When I should use each method.
> > 2. Currently, when I resize a frame, the JTextBoxes will resize for
> > part of the time and then, as the JFrame gets smaller, they will
> > collapse to an extremely small size (1 character wide...if that). *Do
> > I *have* to use setMinimumSize to prevent this from happening?/

>
> > Thanks for any info. *Appreciate it.

>
> The answer is it depends a lot on the layout manager that you are using.
>
> The collapsing into a one pixel size makes me think that you are using
> GridBagLayout. *GridBagLayout can be configured to pay attention to
> preferred and minimum size. *I just tried it with my GridBagLayout
> Tester JApplet and it appears not to honor maximum size.
>
> So assuming you are using GridBagLayout the answer is yes you have to
> set the minimum size. *But remember if you shrink the container beyond
> that which will hold the components at minimum size, they will disappear.
>
> Feel free to play with my GridBagLayout Tester JApplet
>
> http://rabbitbrush.frazmtn.com/gridbagtester.html
>
> --
>
> Knute Johnson
> email s/knute/nospam/
>
> --
> Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
> * * * ------->>>>>>http://www.NewsDemon.com<<<<<<------
> Unlimited Access, Anonymous Accounts, Uncensored Broadband Access


That's a nice tool. Thanks, Knute.
 
Reply With Quote
 
Daniele Futtorovic
Guest
Posts: n/a
 
      05-23-2008
On 2008-05-23 17:34 +0100, Jason Cavett allegedly wrote:
> I'm a little confused when I should use the various JComponent
> methods: setPreferredSize, setMinimumSize and setSize. From what I
> can tell:
>
> setPreferredSize(Dimension) - This is (obviously) the preferred size
> of the component. As far as I can tell, this is used to determine
> what size the component should be when pack() is used.
>
> setMinimumSize - The component cannot be any smaller than this.
>
> setSize - Set the current size (hard value).
>
>
> What I'm confused about is...
> 1. When I should use each method.
> 2. Currently, when I resize a frame, the JTextBoxes will resize for
> part of the time and then, as the JFrame gets smaller, they will
> collapse to an extremely small size (1 character wide...if that). Do
> I *have* to use setMinimumSize to prevent this from happening?/
>
>
> Thanks for any info. Appreciate it.


.... you forgot MaximumSize in the lot.

What others said notwithstanding, minimum, preferred and maximum size
come into use especially when you're designing your own components, as a
means to indicate how they ought to behave in LayoutManagers. Legacy
components usually already have a specific and more or less definite
behaviour with regards to that.

--
DF.
to reply privately, change the top-level domain
in the FROM address from "invalid" to "net"
 
Reply With Quote
 
Michael Jung
Guest
Posts: n/a
 
      05-25-2008
Daniele Futtorovic <(E-Mail Removed)> writes:
> On 2008-05-23 17:34 +0100, Jason Cavett allegedly wrote:
>> I'm a little confused when I should use the various JComponent
>> methods: setPreferredSize, setMinimumSize and setSize. From what I
>> can tell:
>>
>> setPreferredSize(Dimension) - This is (obviously) the preferred size
>> of the component. As far as I can tell, this is used to determine
>> what size the component should be when pack() is used.
>>
>> setMinimumSize - The component cannot be any smaller than this.
>>
>> setSize - Set the current size (hard value).
>>
>> What I'm confused about is...
>> 1. When I should use each method.
>> 2. Currently, when I resize a frame, the JTextBoxes will resize for
>> part of the time and then, as the JFrame gets smaller, they will
>> collapse to an extremely small size (1 character wide...if that). Do
>> I *have* to use setMinimumSize to prevent this from happening?/
>>
>> Thanks for any info. Appreciate it.

>
> ... you forgot MaximumSize in the lot.
>
> What others said notwithstanding, minimum, preferred and maximum size
> come into use especially when you're designing your own components, as a
> means to indicate how they ought to behave in LayoutManagers. Legacy
> components usually already have a specific and more or less definite
> behaviour with regards to that.


As a rule of thumb, which hasn't betrayed me so far, consider that the
getters are called by the layout managers and the results are
honoured. That does not preclude components vanishing (behind window
boundaries) or being oversized (filled with background from the parent
component). The setters are there for symmetry. But the values you
set may or may not be persistent, this is at the discretion of the
component you use it on. The reason is that components often
calculate their sizes depening on their contents, so if their content
changes, their (min, max, pref, actual) sizes change and whatever you
set may become lost - this is most obvious for the actual/current size
and shows that this also depends on the layout of the parent (and
thereby the brothers and sisters of your components). The best thing
to do is to inherit from your favorite component and implement the
getters to suite your needs. (Use anonymous classes, if that is all
you want to change.) Then the layout only depends on how respectful
the layout manager is.

Michael
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Preferred way to size fonts richard HTML 6 11-10-2008 06:17 AM
Re: Preferred way to size fonts Chris F.A. Johnson HTML 19 11-08-2008 11:38 PM
Re: Preferred way to size fonts dorayme HTML 0 11-05-2008 11:56 PM
What is the *preferred* way of defining text size - CCS using %... using "x-small" Shiperton Henethe HTML 117 12-22-2004 01:22 AM
Component preferred size dilemma Kerry Shetline Java 4 12-05-2003 08:29 AM



Advertisments