Re: setting size of elements



Andrew Thompson wrote:
On Sat, 27 Aug 2005 11:21:12 -0400, Frances wrote:


Andrew Thompson wrote:

On Sat, 27 Aug 2005 08:46:59 -0400, Frances wrote:


setSiz() is ignored...

In deference to preferredSize, mostly.

..

getContentPane().add(btn);
  btn.setSize(80,20);

...

Yes. The default layout of Swing root containers is BorderLayout,

.. ...

Have you done the layout tutorial and Swing tutorials mentioned in the GUI FAQ?

...I have read up on this stuff more than you think...


Which leads to the next question.  What in those tutorials
is unclear?  Specifically, and one thing at a time..


..I need to do my applet in swing b/c I need a SplitPane, which you can't do in AWT...


AWT does not provide a JSplitPane, no.

My point was not about AWT/Swing, it was about applet/JApplet,
it was about split SplitPane/JSplitPane*. In the specific instance your were mentioning, the default behaviour of an Applet and JApplet is quite different. For example, they have different default layouts.


So, please avoid old habits and instead be *specific*,
and *exact*.

* And there is no such class as a SplitPane.  Why
do you make the reader guess what you are doing?
Do you think that makes it more 'fun' for them?


..I did manage to do a split pane, but even though I specify rows and columns for each TextArea in each ScrollPane inside the SplitPane, the top half comes out tiny (less than one row..) the button I have underneath is same size as SplitPanel..


OK.. Where is your SSCCE?


I'm going a bit crazy here..


Yes.  I noticed.

Again you are tending to pour out a great long series
of breathless questions.


I snipped them.

It seems you have some basic misunderstandings about
how to use layouts, and we need to sort them one at a time.


However, I will give you one more tip this post.


if you use GridLayout (rows and columns) can u tell it what to put in what rows and in what columns? if so I haven't found it yet...


It depends purely on the *order* in which the components are added. Try adding 16 (20 ..50) labels with text "Label nn" to a GridLayout one at a time and it will become very obvious.

I have, Andrew, I have.. I have sat down and copied A LOT of code from books (for example (all examples SSCCE) http://www.francesdelrio.com/java/ShowGridLayout.java)
and many more (have more examples if you don't believe me...;)
have tried converting some of them to JApplets..
(for example, http://www.francesdelrio.com/java/ShowGridLayoutA.java, compiles fine, but get "applet not initialized" error... and these errors in console:


hjava.lang.ClassCastException
        at sun.applet.AppletPanel.createApplet(AppletPanel.java:617)
        at sun.applet.AppletPanel.runLoader(AppletPanel.java:546)
        at sun.applet.AppletPanel.run(AppletPanel.java:298)
        at java.lang.Thread.run(Thread.java:534)

(Thread error????)

also, elements change size as you resize window.. I don't like that.. I would like to be able to control dimensions of elements and for them to not change dimensions if you change window size.. but oh well...

I have done A LOT of stuff from books, they all look great, when I run into problems is when I try to adapt them to my own needs... ;)

basically I want a swing version of this:

http://www.francesdelrio.com/java/win.html
(code: http://www.francesdelrio.com/java/win.java)
with the JTextAreas in a JSplitPane.. and with JTextAreas exact sizes as they appear here when user opens this applet..
(yes of course I meant JSplitPane, not SplitPane, of course there's no such thing as SplitPane...


also, I DO know default layout for Swing is different.. (BorderLayout.. again, I HAVE been reading up a lot of stuff..)

btw, I love Duke doing cartwheels in applet here..
http://java.sun.com/docs/books/tutorial/uiswing/components/applet.html..
it's so neat...

when I say I don't understand something it's not b/c I'm too lazy to look it up (if you're lazy you have no business trying to become a programmer..) but b/c I don't understand some of the explanations..

here..
http://java.sun.com/docs/books/tutorial/uiswing/components/toplevel.html#contentpane

it says:
"Here's the code that the preceding example uses to get a frame's content pane and add the yellow label to it:


frame.getContentPane().add(yellowLabel, BorderLayout.CENTER);   "

'frame' refers to what exactly? JApplet? or do I create a JFrame? a JRootPane?

ok, have more questions (for example re event-dispatching threads..), but, like you say.. I ask too many questions at once..)







.