See the title. I've tried to change component orientation to RIGHT_TO_LEFT
, but that had a unexpected side effect - it behaves strangely with components with specified preferred size.
(JDK 1.6.0_23, Eclipse VE)
EDIT
Here is the example of this:
We have JFrame
with jMainScrollPane
on it. Inside jMainScrollPane
we place a jMainPanel
. Now set jMainPanel
's preferred size to be narrower than jMainScrollPane
's. jMainPanel
will still take all the space on jMainScrollPane
. Now changejMainScrollPane
's orientation to RIGHT_TO_LEFT
and see what happen.
Sample code (change jMainScrollPane
's orientation to see the difference):
import java.awt.BorderLayout;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class TestFrame extends JFrame {
private JPanel jContentPane = null;
private JScrollPane jMainScrollPane = null;
private JPanel jMainPanel = null;
public TestFrame(){
super();
initialize();
}
private void initialize(){
this.setSize(480, 339);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
private JPanel getJContentPane(){
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJMainScrollPane(), BorderLayout.CENTER);
}
return jContentPane;
}
private JScrollPane getJMainScrollPane(){
if (jMainScrollPane == null) {
jMainScrollPane = new JScrollPane();
jMainScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jMainScrollPane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
jMainScrollPane.setViewportView(getJMainPanel());
}
return jMainScrollPane;
}
private JPanel getJMainPanel(){
if (jMainPanel == null) {
jMainPanel = new JPanel();
jMainPanel.setLayout(new BorderLayout());
jMainPanel.setPreferredSize(new Dimension(30, 30));
}
return jMainPanel;
}
}
EDIT2
Due to the strange nature of this, I've submitted a bug to Oracle. They mailed me a bug link
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7038455
At the moment there is no such bug yet - I suppose, it's being checked.
But still, question is open - is there a workaround or another way?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…