Example usage for java.awt Component RIGHT_ALIGNMENT

List of usage examples for java.awt Component RIGHT_ALIGNMENT

Introduction

In this page you can find the example usage for java.awt Component RIGHT_ALIGNMENT.

Prototype

float RIGHT_ALIGNMENT

To view the source code for java.awt Component RIGHT_ALIGNMENT.

Click Source Link

Document

Ease-of-use constant for getAlignmentX .

Usage

From source file:MainClass.java

public static void main(String[] a) {
    JFrame frame = new JFrame("Alignment Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    String labels[] = { "--", "----", "--------", "------------" };

    JPanel container = new JPanel();
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);//from  w ww.  j  a  v  a 2  s .c  o  m

    for (int i = 0; i < labels.length; i++) {
        JButton button = new JButton(labels[i]);
        button.setAlignmentX(Component.RIGHT_ALIGNMENT);
        container.add(button);
    }

    frame.add(container, BorderLayout.CENTER);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:AlignX.java

public static void main(String args[]) {
    JFrame frame = new JFrame("X Alignment");
    Container contentPane = frame.getContentPane();

    Container panel1 = makeIt("R", Component.RIGHT_ALIGNMENT);
    Container panel2 = makeIt("C", Component.CENTER_ALIGNMENT);
    Container panel3 = makeIt("L", Component.LEFT_ALIGNMENT);

    contentPane.setLayout(new FlowLayout());
    contentPane.add(panel1);/*from w w  w .j  a  v a2  s. c o  m*/
    contentPane.add(panel2);
    contentPane.add(panel3);

    frame.pack();
    frame.show();
}

From source file:YAxisAlignX.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Alignment Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container panel1 = makeIt("Left", Component.LEFT_ALIGNMENT);
    Container panel2 = makeIt("Center", Component.CENTER_ALIGNMENT);
    Container panel3 = makeIt("Right", Component.RIGHT_ALIGNMENT);

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new FlowLayout());
    contentPane.add(panel1);/*  ww  w.ja v a2s . c  o  m*/
    contentPane.add(panel2);
    contentPane.add(panel3);

    frame.pack();
    frame.setVisible(true);
}

From source file:YAxisAlignX.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Alignment Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container panel1 = layoutComponents("Left", Component.LEFT_ALIGNMENT);
    Container panel2 = layoutComponents("Center", Component.CENTER_ALIGNMENT);
    Container panel3 = layoutComponents("Right", Component.RIGHT_ALIGNMENT);
    frame.setLayout(new FlowLayout());
    frame.add(panel1);/*from   w  ww .  j ava2  s.  c o  m*/
    frame.add(panel2);
    frame.add(panel3);

    frame.pack();
    frame.setVisible(true);
}

From source file:YAxisDiffAlign.java

private static Container makeIt(String title, boolean more) {
    JPanel container = new JPanel() {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Insets insets = getInsets();
            int width = getWidth() - insets.left - insets.right;
            int halfWidth = width / 2 + insets.left;
            int height = getHeight();
            int halfHeight = height / 2 + insets.top;
            g.drawLine(halfWidth, 0, halfWidth, height);
        }/*from w ww  . ja v  a2  s  . c o  m*/
    };
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);

    JButton button;
    button = new JButton("0.0");
    button.setOpaque(false);
    button.setAlignmentX(Component.LEFT_ALIGNMENT);
    container.add(button);
    if (more) {
        button = new JButton(".25");
        button.setOpaque(false);
        button.setAlignmentX(0.25f);
        container.add(button);
        button = new JButton(".5");
        button.setOpaque(false);
        button.setAlignmentX(Component.CENTER_ALIGNMENT);
        container.add(button);
        button = new JButton(".75");
        button.setOpaque(false);
        button.setAlignmentX(0.75f);
        container.add(button);
    }
    button = new JButton("1.0");
    button.setOpaque(false);
    button.setAlignmentX(Component.RIGHT_ALIGNMENT);
    container.add(button);

    return container;
}

From source file:org.quackedcube.impl.Gui.java

public JComponent generateContent() {
    //Inital creation
    JPanel clockPanel = new JPanel(new BorderLayout());
    JPanel virtualCubePanel = new JPanel(new BorderLayout());
    JPanel logPanel = new JPanel(new BorderLayout());
    virtualCubePanel//from ww w .ja v a  2 s. c  o  m
            .setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Cube Position"));
    logPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Log"));

    //Clock setup
    clock = new Clock();
    clock.setPreferredSize(new Dimension((int) clock.getPreferredSize().getWidth(), 100));
    clock.setFont(new Font("Arial", Font.PLAIN, 180));
    clock.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Timer"));
    clock.setAlignmentX(JComponent.CENTER_ALIGNMENT);
    clockPanel.add(clock, BorderLayout.CENTER);

    //Logging panel setup
    logScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    logScroll.setAlignmentX(Component.RIGHT_ALIGNMENT);
    logPane.setEditable(false);
    logPane.setAlignmentX(Component.CENTER_ALIGNMENT);
    logPanel.add(logScroll, BorderLayout.CENTER);

    //Virtual Cube panel
    log.trace("Creating virtual cube");
    virtualCubePanel.add(virtualCube = new VirtualBuilder(), BorderLayout.CENTER);
    log.trace("Done creating virtual cube.");
    JPanel virtualCubeControl = new JPanel(new FlowLayout());
    virtualCubeControl.add(new JButton("Rotate") {
        {
            final JButton self = this;
            addActionListener(new ActionListener() {
                final String start = "Rotate";
                final String end = "Stop Rotating";

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (self.getText().equals(start)) {
                        Gui.this.virtualCube.rotate();
                        self.setText(end);
                    } else if (self.getText().equals(end)) {
                        Gui.this.virtualCube.stopRotating();
                        self.setText(start);
                    }
                }
            });
        }
    });
    virtualCubeControl.add(new JButton("Reset Position") {
        {
            addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    Gui.this.virtualCube.resetPosition();
                }
            });
            setEnabled(false);
        }
    });
    virtualCubePanel.add(virtualCubeControl, BorderLayout.SOUTH);

    log.trace("Creating content pane");
    JPanel contentPane = new JPanel(new MigLayout("fill", "fill", "fill"));
    contentPane.add(clock, "dock north"); //span 2, hmax 25%, wrap
    contentPane.add(virtualCubePanel, "growprio 20");
    contentPane.add(logPanel, "span 1 2");

    return contentPane;
}

From source file:lisong_mechlab.view.graphs.DamageGraph.java

/**
 * Creates and displays the {@link DamageGraph}.
 * //from   w  w  w .  j a v a 2  s  . co  m
 * @param aLoadout
 *            Which load out the diagram is for.
 * @param anXbar
 *            A {@link MessageXBar} to listen for changes to the loadout on.
 * @param aMaxSustainedDpsMetric
 *            A {@link MaxSustainedDPS} instance to use in calculation.
 */
public DamageGraph(LoadoutBase<?> aLoadout, MessageXBar anXbar, MaxSustainedDPS aMaxSustainedDpsMetric) {
    super("Max Sustained DPS over range for " + aLoadout);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    anXbar.attach(this);

    loadout = aLoadout;
    maxSustainedDPS = aMaxSustainedDpsMetric;
    chartPanel = new ChartPanel(makechart());
    setContentPane(chartPanel);
    chartPanel.getChart().getLegend().setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chartPanel.getChart().getLegend().setVerticalAlignment(VerticalAlignment.TOP);

    LegendTitle legendTitle = chartPanel.getChart().getLegend();
    XYTitleAnnotation titleAnnotation = new XYTitleAnnotation(0.98, 0.98, legendTitle,
            RectangleAnchor.TOP_RIGHT);
    titleAnnotation.setMaxWidth(0.4);
    ((XYPlot) (chartPanel.getChart().getPlot())).addAnnotation(titleAnnotation);
    chartPanel.getChart().removeLegend();

    chartPanel.setLayout(new OverlayLayout(chartPanel));
    JButton button = new JButton(
            new OpenHelp("What is this?", "Max-sustained-dps-graph", KeyStroke.getKeyStroke('w')));
    button.setMargin(new Insets(10, 10, 10, 10));
    button.setFocusable(false);
    button.setAlignmentX(Component.RIGHT_ALIGNMENT);
    button.setAlignmentY(Component.BOTTOM_ALIGNMENT);
    chartPanel.add(button);

    setIconImage(ProgramInit.programIcon);
    setSize(800, 600);
    setVisible(true);
}

From source file:lisong_mechlab.view.graphs.SustainedDpsGraph.java

/**
 * Creates and displays the {@link SustainedDpsGraph}.
 * /*w ww . ja v a 2 s .com*/
 * @param aLoadout
 *            Which load out the diagram is for.
 * @param aXbar
 *            A {@link MessageXBar} to listen for changes to the loadout on.
 * @param aMaxSustainedDpsMetric
 *            A {@link MaxSustainedDPS} instance to use in calculation.
 */
public SustainedDpsGraph(LoadoutBase<?> aLoadout, MessageXBar aXbar, MaxSustainedDPS aMaxSustainedDpsMetric) {
    super("Max Sustained DPS over range for " + aLoadout);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    aXbar.attach(this);

    loadout = aLoadout;
    maxSustainedDPS = aMaxSustainedDpsMetric;
    chartPanel = new ChartPanel(makechart());
    setContentPane(chartPanel);

    chartPanel.setLayout(new OverlayLayout(chartPanel));
    JButton button = new JButton(
            new OpenHelp("What is this?", "Max-sustained-dps-graph", KeyStroke.getKeyStroke('w')));
    button.setMargin(new Insets(5, 5, 5, 5));
    button.setFocusable(false);
    button.setAlignmentX(Component.RIGHT_ALIGNMENT);
    button.setAlignmentY(Component.TOP_ALIGNMENT);
    chartPanel.add(button);

    setIconImage(ProgramInit.programIcon);
    setSize(800, 600);
    setVisible(true);
}

From source file:org.jdal.swing.form.FormUtils.java

/**
 * Create a box with an aligned component using Component constants for right, center and left.
 * @param c component//  w  ww  .j  a  va 2  s  . c om
 * @param alignment aligment.
 * @return Box with compoenent
 */
public static Component newBoxForComponent(Component c, float alignment) {
    Box box = Box.createHorizontalBox();
    if (Component.RIGHT_ALIGNMENT == alignment) {
        box.add(Box.createHorizontalGlue());
        box.add(c);
    } else if (Component.CENTER_ALIGNMENT == alignment) {
        box.add(Box.createHorizontalGlue());
        box.add(c);
        box.add(Box.createHorizontalGlue());
    } else {
        // default to left
        box.add(c);
        box.add(Box.createHorizontalGlue());
    }

    return box;
}

From source file:gg.pistol.sweeper.gui.component.DecoratedPanel.java

/**
 * Helper method to set the right alignment.
 *
 * @param component/*from w  w  w .  j a v a2s .  c o  m*/
 *         the component to align
 * @return the aligned component
 */
protected <T extends JComponent> T alignRight(T component) {
    return alignHorizontally(component, Component.RIGHT_ALIGNMENT);
}