This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

applyComponentOrientation: am i misunderstanding or something else...?  RSS feed

 
Esmaeil Ashrafi
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i think the SSCCE will explain better:


As you will see after running the program, i expect (based on documentations for method applyComponentOrientation in Container) that not only childes of frame's content pane, but also childes of its childes (here is the buttons contained in panel) to be oriented as ordered.

Any explanation to clear me will be much appreciated.

P.S: I know i can use setComponentOrientation for each container, but if applyComponentOrientation does just as it declares, will be very efficient...
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is it that's not working for you? When I run it, I see the JPanel named panel on the right, and button1 on the left.
The RTL orientation was set on the content pane for the JFrame, so this seems correct.

What seems confusing about this code is the labels used on the two buttons placed in panel. They imply that the buttons will be positioned RTL within panel, but RTL orientation was not set on panel, so they seem to be laid out correctly to me.

 
Esmaeil Ashrafi
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see exactly what you see!
I know RTL for content pane childes applied, well, but i should say this for second time:
based on documentations for method applyComponentsOrientation, below:

Sets the ComponentOrientation property of this container and all components contained within it


So i expect the panel set to RTL automaticalyy because of using this method.
I labeled the buttons in panel to clarify the issue.

another matter of fact is if applyComponentOrientation just does same thing as setComponentOrientation, what's the difference ?!
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The documentation for Component.setComponentOrientation() says that it will apply to the component only, while the documentation for Component.applyComponentOrientation() says that it will apply to the component and all components contained within it.

I wonder if your panel is not affected because it is added to the container after making the applyComponentOrientation() call? Try making that call after adding everything to see what happens.

Otherwise, I'm not sure what is happening.
 
Esmaeil Ashrafi
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark E Hansen wrote:...
I wonder if your panel is not affected because it is added to the container after making the applyComponentOrientation() call? Try making that call after adding everything to see what happens.
...


Excellent, twice excellent, more excellent to you
I wanted to prepare myself to say "No difference", but took your suggestion and that worked perfect !
(i just applied the orientation in line #27 of SSCCE)
This was really annoying me, because i had to type more extra codes and setComponentOrientation for each component seperately and ...to make GUI of my application RTL oriented.
And this was a while i wa thinking about that and today decided to write an example and ask the Ranch to help

Thank you very much Mark
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!