From: Roedy Green on
On Sun, 21 Feb 2010 15:26:57 -0800 (PST), Nessuno <fmdf66(a)gmail.com>
wrote, quoted or indirectly quoted someone who said :

>
>I am a newbie in Java. While learning from the Horstmann I have
>modified a little example from the book. The problem is that the
>buttons it creates are never shown.

See http://mindprod.com/jgloss/jbutton.html
and
http://mindprod.com/jgloss/button.html

for some similar sample code that does work.

Hint: Every Component except the Frame/JFrame must be added to some
container to be visible.
--
Roedy Green Canadian Mind Products
http://mindprod.com

When a newbie asks for help tracking a bug in a code snippet, the problem is usually is the code he did not post, hence the value of an SSCCE.
see http://mindprod.com/jgloss/sscce.html
From: markspace on
Knute Johnson wrote:

> He calls setSize() in the JFrame constructor. Not the best method but
> it does work in this instance.


Thanks, I'd missed that. I think I might recommend calling pack() after
adding all components, then calling setMinimumSize() instead of
setSize(). That'll prevent the components from clipping if they take
more space, but will enlarge the window if it happens to be smaller.

From: Lew on
Nessuno wrote:
> public class ButtonTest
> {
> public static void main( String[] args )
> {
> EventQueue.invokeLater(new Runnable()
> {
> public void run()
> {
> ButtonFrame frame = new ButtonFrame();

As others have answered your question, I will only add that you should not
indent Usenet code examples with TAB characters, as they get ridiculously wide
for most newsreaders and gravely harm readability. You want your code to be
readable. Please use spaces, up to a maximum of four per indent level, for
indentation.

--
Lew
First  |  Prev  | 
Pages: 1 2
Prev: Java app installer
Next: ArrayList issue