Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Orientational Problems

Status
Not open for further replies.

kmcculler

Programmer
Jul 5, 2000
81
0
0
US
Hey guys, I'm having some problems with getting my app to display correctly with RTL (RIGHT_TO_LEFT) orienation. The two components giving me the biggest headache are JScrollPane and JFrame. Im using java 1.4 and setting applyComponentOrientation(ComponentOrienation.RIGHT_TO_LEFT) on all the components.
When I do an set orientation on my JScrollPane the scrollbars switch sides as their supposed to, but they view still starts out on the top left side. Since the orienation is RTL I want the horizontal scrollbar to be all the way to the right when the component becomes visual (top-right corner). I see in the API that JScrollPane has its own setComponentOrienation and this is supposed to effect the scrollbars but after trying it I still got the upper left corner.
The second issue is JFrame. I also set orienation on this component and looking at sun's documentation its supposed to be fully compatable with orienation. In all my examples I am still getting a frame with the title on the left and the min/max/close buttons on the right.
This is just a quick mock up of code that illustrates both my problems:
Code:
import javax.swing.*;
import java.awt.*;
import javax.swing.plaf.basic.BasicComboBoxRenderer;

public class OrTest extends JFrame {
	public OrTest() {
		super("Frame Title");
		setSize(300,100);
		setLocation(200,150);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		JPanel pane = new JPanel();
		JScrollPane  jsp = new JScrollPane();
		JLabel lbl = new JLabel("This is a very long piece of text so that I can test JScrollPane's ability to do right to left orientation. The scroll bar should set the viewing area all the way to the right hand side of this label.");


		applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
		pane.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
		//jsp.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
		jsp.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
		lbl.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

		pane.add(lbl);
		jsp.setViewportView(pane);
		setContentPane(jsp);
		setVisible(true);

	}

	public static void main(String[] args) {
		OrTest ot = new OrTest();
	}
}

Can anybody help me with both or either of these components? Thanks in advance.


Kris McCuller
 
no way I stumped everybody? come on guys!

Kris McCuller
 
There is one element in both the panel and the scroll pane... It seems to me that anywhere it puts it can be intrepted as filling from left to right or right to left. You'd need to add another element to see the order that it is filling in... As far as the panel and scroll are concerned. You may want to also look into alignment and even layout. The only thing setComponentOrientation() deals with is language type stuff. Positioning is generally layout stuff.

[plug=shameless]
[/plug]
 
I don't think your understanding my problem. My issue isn't with layout of components, I'm having problems with the titlebar of the JFrame and the default postion of the horizontal scrollbar on the JScrollPane not being correctly oriented to display my app in Hebrew.
Hebrew is read right-to-left instead of left-to-right like English. SetComponentOrienation is supposed to flip the swing components to display for languages not using the same left-to-right top-to-bottom method we do. For the most part it works, I just have a few issues as listed above.
Unfortunatly layout and alighment adjustments don't fix my issues.

Kris McCuller
 
well, I was finally able to solve my JFrame problem by adding the following to my example:
Code:
setUndecorated(true);		getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
it picked up the look and feel from the pane and then oriented correclty... apparently JFrame doesn't play by the same rules as other compoents and was ignoring the orientation in favor of the os.
Still haven't figured out my scrollpane issue though.

Kris McCuller
 
I traced down the JScrollPane problem to the ScrollPaneLayout class, by searching through the jdk 1.3 source.

From what I can see, the vertical scrollbar is hardcoded to be on the right side. The guilty line seems to be:

Code:
Rectangle vsbR = new Rectangle(0, availR.y - vpbInsets.top, 0, 0);

Perhaps you could subclass it and override the layoutContainer method to fix it.
 
Haven't been able to make this work yet, but I'm still hackin on it. Seems there should be an easier way to set the viewable portion of a scrollpane though, force it to show the upper right of the screen....

Kris McCuller
 
Ok, finnally got it to work and I did manage to find a simpler way to do it... a one liner infact.
Code:
jsp.getViewport().setViewPosition(new Point(jsp.getMaximumSize().width,0));

Kris McCuller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top