• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question on ComponentEvent behavior  RSS feed

 
Tom Landry
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the code from the Java Docs (listed below) I am getting behavior that was a bit unexpected.
The only changes were to add JTextField and additional output within the ComponentEvent handlers.

Run the code and when the frame appears, think of each side as North, South, East (right side) and West (left side) as you are looking at it.
This was run using JDK 1.7.0_25.

Run the code.
1 - Click the East edge (right) of the frame and drag to be wider or more narrow. Only the "Resized" is executed for all components which makes sense.
2 - Click the West edge (left) of the frame and drag to be wider or more narrow. This time "Resized" is executed for all components EXCEPT it is "Moved" for JFrame.
Why is it "Moved" here for JFrame but not in Step 1?

3 - Click the South edge (bottom) of the frame and drag to be taller or shorter. This time only 2 components are affected. JPanel is "Moved" while JFrame is "Resized".
Why isn't both JFrame and JPanel just "Resized"?

4 - Click the North edge (top) of the frame and drag to be taller or shorter. This time only 2 components are affected again but the output is slightly different.
JPanel is "Moved" while JFrame is BOTH "Resized" and "Moved".

There just doesn't seem to be consistency here.

What are the guidelines or criteria for when these Events are to be executed?
Anytime I think of one it may fit one or two scenarios but not all four.

 
Rob Camick
Ranch Hand
Posts: 2756
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you resize the right/bottom of a frame then change the size of the frame.

When you resize the left/top of the frame you change the size but then you also need to adjust the location of the frame relative to the screen.
 
Tom Landry
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:When you resize the right/bottom of a frame then change the size of the frame.



When using the right all Components are "Resized".
When using the bottom just JFrame is "Resized" and JPanel is "Moved".
Why is it "Moved" when the location hasn't changed?


Rob Camick wrote:

When you resize the left/top of the frame you change the size but then you also need to adjust the location of the frame relative to the screen.


When using the top, JPanel and JFrame are "Moved" and JFrame is also "Resized".
Why isn't JPanel "Resized" too?

When using the left side JPanel and JFrame are "Resized" and JFrame is also "Moved".
Why isn't JPanel "Moved" with both top and left? Why only with top?
 
Rob Camick
Ranch Hand
Posts: 2756
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read up on how the BorderLayout works. See: How to Use a Border Layout.

The "moved" event for the panel is generated when its location changes relative to its parent.

Resizing left/right does not change the location of the panel, only the width.

Resizing up/down does not change the height of the panel, only the location.
 
Tom Landry
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:Read up on how the BorderLayout works. See: How to Use a Border Layout.

The "moved" event for the panel is generated when its location changes relative to its parent.

Resizing left/right does not change the location of the panel, only the width.

Resizing up/down does not change the height of the panel, only the location.


Is all this based on the bottom section where the hard coded Text, Checkbox and TestFields are located?
I am viewing it as the entire form which includes the TextArea that gets all the output.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!