Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Relocating Content Pane  RSS feed

 
Rahul Saple
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What ive got is a few lines of code....

and what im trying to do here is move/relocate the content pane to a different position...... but im failing to do so..... The code compiles and runs just fine..... what little i know abt swing tells me that in order to manually position a component, the layout manager of the container(JLayeredPane) should be null which it is in this case...... Im sure its something very elementary that im missing here...... Thanks....
[ November 13, 2008: Message edited by: rahul saple ]
 
Brian Cole
Author
Ranch Hand
Posts: 949
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rahul saple:
What ive got is a few lines of code....

and what im trying to do here is move/relocate the content pane to a different position...... but im failing to do so..... The code compiles and runs just fine..... what little i know abt swing tells me that in order to manually position a component, the layout manager of the container(JLayeredPane) should be null which it is in this case...... Im sure its something very elementary that im missing here......


What is your goal in relocating the content pane? The content pane
is designed to fill your Frame, and I can't think of a situation where
you would want anything different.

If you want to relocate the Frame itself, then fine, just do that.

Otherwise it is the RootPane that lays out the content pane, not the
layered pane. getContentPane() defers to getRootPane().getContentPane(),
and getRootPane().getLayout() will not return null. (It should return an
instance of RootLayout, a non-public nested class.)

[edit: sorry, had some posting troubles]
[ November 13, 2008: Message edited by: Brian Cole ]
 
Rahul Saple
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Brian thanks for that prompt reply.......... im actually trying to give the JFrame a more customized feel ....like the one i get by adding these two lines to my code...

The following code results in a Jpanel placed on top of the contentpane with the content pane shrunk accordingly. I checked that part by listing all the components in the frame..... the JPanel is not a part of the content pane..... I was wondering if id wish to give it a customized feel id eventually want to relocate the content pane myself ...

Otherwise it is the RootPane that lays out the content pane, not the
layered pane.

But isnt content pane's immediate parent the layered pane ...... sorry if its a silly question...... but i always thought that the immediate parent's layout is what determines how its children are positioned... correct me if im wrong........ Thanks a tonne......
[ November 13, 2008: Message edited by: rahul saple ]
 
Brian Cole
Author
Ranch Hand
Posts: 949
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rahul saple:
results in a Jpanel placed on top of the contentpane with the content pane shrunk accordingly. I checked that part by listing all the components in the frame..... the JPanel is not a part of the content pane.....


I'm not sure which JPanel you're talking about.

I was wondering if id wish to give it a customized feel id eventually want to relocate the content pane myself ...


I think it's probably best to do this within the system instead of
trying to use setBounds() and a null layout manager. The RootLayout
layout manager will respect the JRootPane's insets and border (and
also the height of the JMenuBar if it has one).


But isnt content pane's immediate parent the layered pane ...... sorry if its a silly question...... but i always thought that the immediate parent's layout is what determines how its children are positioned... correct me if im wrong........


Almost always. If you take a look at the source code for JRootPane, you
will see that the JLayeredPane's components are actually laid out by the
JRootPane's layout manager. Crazy, eh? They even put this comment in
the code:

[edit: fix unbalanced QB and QUOTE tags]
[ November 13, 2008: Message edited by: Brian Cole ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!