Component size problem! Resizes to parent's size for reasons I'm unaware of?

Firstly, that is an awful lot of code. You want to be able to cut the problem down so that it is small enough that it becomes trivial. And if you want other people to help, it's generally a good idea to be able to produce a complete, compilable program that shows the problem and nothing else.

Firstly, that is an awful lot of code. You want to be able to cut the problem down so that it is small enough that it becomes trivial. And if you want other people to help, it's generally a good idea to be able to produce a complete, compilable program that shows the problem and nothing else.As it is, it looks as if you are using the content pane of a JFrame with the default LayoutManager.

This will default to BorderLayout. When you add components without specifying constraints, they will be added to the "center". Without any side components, the center component will spread out to fill all available area.

So set an appropriate layout manager. I prefer to create a JPanel and use setContentPane, rather than have to bend my code structure around getContentPane.

1 for spotting the default LayoutManager. Even more convenient, the add() method of JFrame will forward to the contentPane: java.sun. Com/javase/6/docs/api/javax/swing/JFrame.

Html – trashgod Jan 24 '10 at 16:41 You're absolutely right, thanks for pointing this out. Thank you so much. – Dois Jan 24 '10 at 18:34.

If that's the case, I'll try JComponent. – Dois Jan 24 '10 at 16:01 I haven't looked through your code, but yes, I do think Swing has a much more flexible layout behaviour, so I would recommend to try. AWT is not a faster version of Swing - AWT is much more limited and much less portable and much less updated.So in general, AWT is not often recommended, unless there is a very good reason.

I do hope you will be able to reach proper frame rates with Swing - but make sure you understand Swing behaviour first if you seem to have problems there (look for Swing component tutorials and read up on how Swing does painting). – Bandi-T Jan 24 '10 at 16:16.

Eh... For some very strange reason unbeknownst to me, when I add this line right below the run() method... try { Clip clip = AudioSystem.getClip(); //More to be written } catch (Exception e) {} The paddle renders (correct size) correctly. When I remove it, the problem comes back... so... what the heck? Try { //Clip clip = AudioSystem.getClip(); //More to be written } catch (Exception e) {}.

1 The obvious reason why that make a difference is that it changes timing, and therefore can alter the outcome of race conditions. Swing or AWT, always stick to manipulating anything to do with components on the Event Dispatch Thread (EDT). Get into the EDT (even from your main!) with the boilerplate java.awt.EventQueue.

InvokeLater(new Runnable() { public void run() { ...probably call a method here... }});. This applies to AWT as well as Swing, as AWT is full of threading bugs, and is probably a theoretical impossibility to correct. – Tom Hawtin - tackline Jan 24 '10 at 19:37 Oh gosh... I think you just solved a different problem I've been having.

I was confUZZLED as to why my server and client programs couldn't talk to each other - my socketX. Write(STUFF) was fine but the socketY. Read(STUFF) wasn't reading properly for some reason it would always seem 1 step slower than it should be... my friend later had the same problem and found that if he did a socketY.readObject() so the one writing has to send a null object after the usual read(STUFF), the program would work fine.

I guess it's these threading bugs that's causing the problem... – Dois Jan 26 '10 at 16:48.

You might like this Java 2D games tutorial, featuring a Breakout style game.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions