>>setSiz() is ignored...
>
[quoted text clipped - 30 lines]
> Have you done the layout tutorial and Swing tutorials
> mentioned in the GUI FAQ?
>>>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.

Signature
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"Where I'm going next, I'm goin' alone.."
Paul Kelly 'Deeper Water'
Frances - 27 Aug 2005 22:52 GMT
>>>>setSiz() is ignored...
>>>
[quoted text clipped - 67 lines]
> "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..)
Andrew Thompson - 28 Aug 2005 07:38 GMT
...
> basically I want a swing version of this:
>
> http://www.francesdelrio.com/java/win.html
> (code: http://www.francesdelrio.com/java/win.java)
<sscce>
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Win extends JApplet implements ActionListener {
JTextArea ta;
JTextArea ta2;
JButton btn;
FlowLayout layout = new FlowLayout(FlowLayout.LEFT);
public void init() {
ta = new JTextArea("", 14, 35);
ta2 = new JTextArea("", 6, 35);
btn = new JButton("SEND");
//ta.setSize(430,80);
//ta2.setSize(430,50);
Container c = getContentPane();
c.setLayout(layout);
c.add(new JScrollPane(ta, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER ));
c.add(new JScrollPane(ta2, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
c.add(btn);
//btn.setSize(80,20);
btn.addActionListener(this);
}
public void sendMsg() {
String msg = ta2.getText();
//System.out.println(msg);
ta.append(msg + "\n");
ta2.setText("");
// ta.transferFocus();
ta2.requestFocus();
}
public void actionPerformed(ActionEvent ae) {
sendMsg();
}
}
</sscce>
> with the JTextAreas in a JSplitPane..
Put the JScrollPanes in a JSplitPane.
> ...and with JTextAreas exact sizes
Not practical. Java Layouts are intended to give your
UI a logical layout across a variety of PLAFS (including
the tweaks that Sun might do to the default PLAF's
from release to release) using a number of screen
resolutions/ fonts...
Java GUI design is not geared towards giving pixel perfect
representations of UI components, but instead presenting them
at the exact size the end user requires.
Your attempts to create pixel perfect layouts are a
pointless waste of time, and they may be what a developer
wants, but they are rarely what the end user wants.
> 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..
You should stop at each one and ask. You end up
a) wasting too much time trying to force Java layouts to
fit your misconceptions.
b) Tying yourself up in 'code knots'.
> here..
> http://java.sun.com/docs/books/tutorial/uiswing/components/toplevel.html#contentpane
[quoted text clipped - 7 lines]
> 'frame' refers to what exactly? JApplet? or do I create a JFrame? a
> JRootPane?
??? What would make you think that example that mentions 'frame'
would be referring to an 'applet'?
The process of adding things to a Swing content pane is the
same for both, but I thought that would have been pretty clear
they were referring to a JFrame in that example. (and that
is based purely on the snippets you quoted!)

Signature
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"Watch TV and drink your beer."
Charles Manson 'Sick City'
Frances - 28 Aug 2005 12:29 GMT
> ...
>
[quoted text clipped - 96 lines]
> they were referring to a JFrame in that example. (and that
> is based purely on the snippets you quoted!)
Andrew thank you so much!!!!! :) that was perfect!!
(I see that all the ActionListener stuff is the same for Swing as for
AWT... (I thought you weren't supposed to mix AWT and Swing...;)
(I guess goes only for visual elements....)
again, many thanks.. Frances
Andrew Thompson - 28 Aug 2005 13:46 GMT
> (I see that all the ActionListener stuff is the same for Swing as for
> AWT... (I thought you weren't supposed to mix AWT and Swing...;)
I hate that statement. At least that statement unqualified.
- Every Swing component extends an AWT component
- The vast majority of layouts are AWT
- Keyboard, Window, Mouse, Action.. events all
originate from the AWT
- D'n'D is all in the AWT..
Learners get the impression that they can ignore all
of the AWT if they are working with Swing, but you
just need to look at the imports of most Swing code
to realise how much of 'Swing' programming requires
a broad knowledge of the AWT.
> (I guess goes only for visual elements....)
Yep.
> ..again, many thanks.. Frances
No worries. :-)

Signature
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"I have to turn my head, until my darkness goes"
The Rolling Stones 'Paint It Black'