<AWT Dev> Setting a component orientation in JRSUI

Mike Swingler swingler at apple.com
Mon Feb 3 15:10:53 PST 2014


On Jan 22, 2014, at 7:23 AM, Alexander Scherbatiy <alexandr.scherbatiy at oracle.com> wrote:

> Hello,
> 
> Below is the code that shows that setting a component orientation for the JProgressBar in Aqua L&F does not work.
> 
>  My assumption was that the Direction should be properly set to the painter state in the AquaProgressBarUI like:
>  -----------------------------
>    public void paint(final Graphics g, final JComponent c) {
>       ...
>       painter.state.set(c.getComponentOrientation().isLeftToRight() ? Direction.RIGHT : Direction.LEFT);
>    }
>  -----------------------------
> but it does not work.
> 
> The painter calls the JRSUI library to show components on Mac OS X.
> 
> Is there any specification for the JRSUI library?
> What is the right way to set the component direction in the JRSUI.
> 
> Thanks,
> Alexandr.
> 
> 
> ------------------  Code Sample  ----------
> import java.awt.*;
> import java.awt.event.*;
> import javax.swing.*;
> 
> public class JProgressBarOrientationTest {
> 
>    static boolean leftToRight = true;
> 
>    public static void main(String[] args) throws Exception {
> 
>        SwingUtilities.invokeLater(new Runnable() {
> 
>            @Override
>            public void run() {
>                JFrame frame = new JFrame();
>                frame.setSize(300, 200);
> 
>                final JProgressBar progressBar = new JProgressBar(0, 100);
>                progressBar.setValue(30);
> progressBar.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
> 
>                JButton button = new JButton("Change orientation");
>                button.addActionListener(new ActionListener() {
> 
>                    @Override
>                    public void actionPerformed(ActionEvent e) {
>                        leftToRight = !leftToRight;
> progressBar.setComponentOrientation(leftToRight ? ComponentOrientation.LEFT_TO_RIGHT : ComponentOrientation.RIGHT_TO_LEFT);
>                    }
>                });
> 
>                JPanel panel = new JPanel(new BorderLayout());
>                panel.add(progressBar, BorderLayout.CENTER);
>                panel.add(button, BorderLayout.SOUTH);
>                frame.getContentPane().add(panel);
>                frame.setVisible(true);
>            }
>        });
>    }
> }
> -------------------------------------

There is no spec for the JRSUI library, since it's generally a passthrough to underlying undocumented API.

In this case, there is no right-to-left version of the progress bar in OS X. You can confirm this by building a sample app in Xcode, and running it in an RTL language like Hebrew or Arabic.

The code above looks like it should do the right thing if/when the underlying OS does the right thing.

Regards,
Mike Swingler
Apple Inc.



More information about the awt-dev mailing list