Example usage for java.awt Component LEFT_ALIGNMENT

List of usage examples for java.awt Component LEFT_ALIGNMENT

Introduction

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

Prototype

float LEFT_ALIGNMENT

To view the source code for java.awt Component LEFT_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);/* ww  w .  j  av a  2  s  .  c  o  m*/

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

    frame.add(container, BorderLayout.CENTER);

    frame.setSize(300, 200);
    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 = 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);/*from   ww  w .j ava2 s .  c  om*/
    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);//  w w w  .  j a v a  2 s .co m
    frame.add(panel2);
    frame.add(panel3);

    frame.pack();
    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  va 2 s  . co m
    contentPane.add(panel2);
    contentPane.add(panel3);

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

From source file:Main.java

public static Component AlignLeft(JComponent component) {
    component.setAlignmentX(Component.LEFT_ALIGNMENT);
    return component;
}

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 .j av a  2 s.  co 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:Main.java

/** Make the given components horizontally-left aligned. */
public static void setLeftAlignment(JComponent... components) {
    setAlignmentX(Component.LEFT_ALIGNMENT, components);
}

From source file:AlphaCompositeDemo.java

public AlphaCompositeDemo() {
    super();//  w ww.  j  a  v a  2 s . c o m
    Container container = getContentPane();

    canvas = new MyCanvas();
    container.add(canvas);

    rulesBox = new JComboBox(rulesLabels);
    rulesBox.setSelectedIndex(0);
    rulesBox.setAlignmentX(Component.LEFT_ALIGNMENT);
    rulesBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JComboBox cb = (JComboBox) e.getSource();
            canvas.compositeRule = rules[cb.getSelectedIndex()];
            canvas.repaint();
        }
    });

    slider.setPaintTicks(true);
    slider.setMajorTickSpacing(25);
    slider.setMinorTickSpacing(25);
    slider.setPaintLabels(true);
    slider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            JSlider slider = (JSlider) e.getSource();
            canvas.alphaValue = (float) slider.getValue() / 100;
            canvas.repaint();
        }
    });

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(1, 3));
    panel.add(rulesBox);
    panel.add(new JLabel("Alpha Adjustment x E-2: ", JLabel.RIGHT));
    panel.add(slider);
    container.add(panel, BorderLayout.SOUTH);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    setSize(500, 300);
    setVisible(true);
}

From source file:pl.kotcrab.arget.gui.session.msg.TextMessage.java

public TextMessage(MsgType type, String text, boolean markAsRead) {
    super(type);//from w  ww .  j  a va 2 s  .c  o m

    textPane = new JTextPane();
    textPane.setAlignmentX(Component.LEFT_ALIGNMENT);
    textPane.setEditorKit(new WrapHTMLEditorKit());
    textPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
    textPane.setEditable(false);
    textPane.setBackground(null);
    textPane.setBorder(new EmptyBorder(3, 3, 0, 0));
    textPane.setFont(textFont);

    textPane.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent hle) {
            if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) {

                if (DesktopUtils.openWebsite(hle.getURL()) == false)
                    JOptionPane.showMessageDialog(null, "Invalid URL: " + hle.getURL(), "Error",
                            JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    setText(text);

    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    add(textPane);

    DateFormat dateFormat = new SimpleDateFormat("[HH:mm] ");
    Date date = new Date();

    String textToShow = dateFormat.format(date);

    if (markAsRead == false)
        textToShow += "*";

    timeLabel = new JLabel(textToShow);
    timeLabel.setBorder(new EmptyBorder(0, 3, 3, 0));
    timeLabel.setForeground(Color.GRAY);
    timeLabel.setFont(smallTextFont);
    add(timeLabel);
}

From source file:ArcApp.java

public ArcApp() {
    super(new BorderLayout());
    canvas = new MyCanvas();
    int width = 600;
    int height = 55;
    sliderX = setSlider(0, width, width / 4, width / 2, width / 4);
    sliderY = setSlider(0, height, height / 4, height / 2, height / 4);
    sliderWidth = setSlider(0, width, width / 2, width / 2, width / 4);
    sliderHeight = setSlider(0, height, height / 2, height / 2, height / 4);
    sliderT0 = setSlider(0, 360, 45, 180, 45);
    sliderT = setSlider(0, 360, 135, 180, 45);

    JPanel panel1 = new JPanel();
    panel1.setLayout(new GridLayout(3, 3));
    panel1.add(new JLabel("Location (x,y): ", JLabel.RIGHT));
    panel1.add(sliderX);/*from ww  w  .  j a  va  2s.  c  o m*/
    panel1.add(sliderY);
    panel1.add(new JLabel("Size (w,h): ", JLabel.RIGHT));
    panel1.add(sliderWidth);
    panel1.add(sliderHeight);
    panel1.add(new JLabel("Angles (Th0, Th): ", JLabel.RIGHT));
    panel1.add(sliderT0);
    panel1.add(sliderT);

    add(panel1, BorderLayout.NORTH);

    arcBox = new JComboBox(arcLabels);
    arcBox.setSelectedIndex(0);
    arcBox.setAlignmentX(Component.LEFT_ALIGNMENT);
    arcBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JComboBox cb = (JComboBox) e.getSource();
            canvas.arcType = arcTypes[cb.getSelectedIndex()];
            canvas.repaint();
        }
    });

    fillBox = new JComboBox(colorLabels);
    fillBox.setSelectedIndex(0);
    fillBox.setAlignmentX(Component.LEFT_ALIGNMENT);
    fillBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JComboBox cb = (JComboBox) e.getSource();
            canvas.fillColor = colors[cb.getSelectedIndex()];
            canvas.repaint();
        }
    });

    JPanel panel2 = new JPanel();
    panel2.setLayout(new GridLayout(1, 4));
    panel2.add(new JLabel("Arc Type: ", JLabel.RIGHT));
    panel2.add(arcBox);
    panel2.add(new JLabel("Fill Type: ", JLabel.RIGHT));
    panel2.add(fillBox);

    add(panel2, BorderLayout.SOUTH);
    add(canvas, BorderLayout.CENTER);
}