Example usage for javax.swing SwingConstants CENTER

List of usage examples for javax.swing SwingConstants CENTER

Introduction

In this page you can find the example usage for javax.swing SwingConstants CENTER.

Prototype

int CENTER

To view the source code for javax.swing SwingConstants CENTER.

Click Source Link

Document

The central position in an area.

Usage

From source file:com.adito.upgrade.Upgrade.java

/**
 * @param args//from  w  w  w. j a  va 2 s  . co  m
 * @throws Exception on any error
 */
public static void main(String[] args) throws Exception {

    boolean gui = System.getProperty("os.name").toLowerCase().startsWith("windows")
            || System.getenv("DISPLAY") != null;

    if (args.length == 2 || !gui) {
        Upgrader upgrader = new CommandLineUpgrader(args);
        upgrader.upgrade();
    } else {
        JFrame f = new JFrame("0.1.16 to 0.2.5+ Upgrader");
        final Upgrader upgrader = new GUIUpgrader();
        f.setIconImage(new ImageIcon(Upgrade.class.getResource("upgrader-32x32.png")).getImage());
        f.getContentPane().setLayout(new BorderLayout());
        f.getContentPane().add((JPanel) upgrader, BorderLayout.CENTER);
        f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        JPanel bp = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        final JButton start = new JButton("Start");
        ;
        final JButton close = new JButton("Close");
        start.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    start.setEnabled(false);
                    close.setEnabled(false);
                    upgrader.upgrade();
                } catch (Exception ex) {
                    upgrader.error("Failed to upgrade.", ex);
                } finally {
                    close.setEnabled(true);
                }
            }
        });
        close.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (close.isEnabled())
                    System.exit(0);
            }
        });
        bp.add(start);
        bp.add(close);
        f.getContentPane().add(bp, BorderLayout.SOUTH);
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent evt) {
                if (close.isEnabled())
                    System.exit(0);
            }
        });
        f.setSize(new Dimension(480, 460));
        UIUtil.positionComponent(SwingConstants.CENTER, f);
        f.setVisible(true);
    }
}

From source file:Main.java

public static void setupNowLoadingPanel(JPanel panel) {
    JLabel loading = new JLabel("Loading...", SwingConstants.CENTER);
    panel.setLayout(new BorderLayout());
    panel.add(loading, BorderLayout.CENTER);
    panel.revalidate();//from   w w w .ja v  a  2  s  . c o m
    panel.repaint();
}

From source file:Main.java

public static Window showBelow(Component parent, Window window) {
    return showBelow(parent, window, SwingConstants.CENTER);
}

From source file:Main.java

public static String layoutComponentCenter(JComponent c, String text, Icon icon, int iconTextGap,
        Rectangle viewRect, Rectangle iconRect, Rectangle textRect) {
    int center = SwingConstants.CENTER;
    return layoutComponent(c, text, icon, iconTextGap, center, center, center, center, viewRect, iconRect,
            textRect);/*from w  w w . j a v  a  2s.  co m*/
}

From source file:Main.java

public static int asHAlign(String val) {
    if (val.equals("leading"))
        return SwingConstants.LEADING;
    else if (val.equals("trailing"))
        return SwingConstants.TRAILING;
    else if (val.equals("left"))
        return SwingConstants.LEFT;
    else if (val.equals("right"))
        return SwingConstants.RIGHT;
    else if (val.equals("center"))
        return SwingConstants.CENTER;

    assert false;
    return -1;/*from  w  ww .j  ava  2  s  . co  m*/
}

From source file:Main.java

/** 
 * Creates a <code>JPanel</code> containing the given text placed in the
 * center as the only component.//ww w  .  j a va  2s.  c o  m
 * @param text - the text to put on the panel
 * @return a JPanel containing only the given text
 */
public static JPanel makeTextPanel(String text) {
    JPanel panel = new JPanel(false);
    JLabel filler = new JLabel(text);
    filler.setHorizontalAlignment(SwingConstants.CENTER);
    panel.setLayout(new GridLayout(1, 1));
    panel.add(filler);
    return panel;
}

From source file:Main.java

public static Window showBelow(Component parent, Window window, int horizontalAlignment) {
    final int DISTANCE = 2;

    if (null == parent)
        throw new IllegalArgumentException("parent null");
    if (null == window)
        throw new IllegalArgumentException("parent null");
    if (!((SwingConstants.LEADING == horizontalAlignment) || (SwingConstants.TRAILING == horizontalAlignment)
            || (SwingConstants.CENTER == horizontalAlignment)
            || (SwingConstants.SOUTH == horizontalAlignment))) {

        throw new IllegalArgumentException("Illegal horizontal alignment " + horizontalAlignment
                + " should be either SwingConstants.LEADING or "
                + "SwingConstants.TRAILING or SwingConstants.CENTER");
    }//from w  ww .j a v  a  2  s .  c  o  m

    window.pack();

    Dimension windowSize = window.getPreferredSize();
    Dimension parentSize = parent.getSize();

    Point loc = parent.getLocationOnScreen();

    int newX;

    if ((SwingConstants.CENTER == horizontalAlignment) || (SwingConstants.SOUTH == horizontalAlignment)) {

        newX = (parentSize.width - windowSize.width) / 2 + loc.x;
    } else if (SwingConstants.TRAILING == horizontalAlignment) {
        newX = loc.x + parentSize.width - windowSize.width;
    } else {
        newX = loc.x;
    }

    window.setLocation(newX, (loc.y + parentSize.height + DISTANCE));

    window.setVisible(true);

    return window;
}

From source file:Main.java

private static int createDefaultHorizontalAlignment() {
    int swingAlign = SwingConstants.RIGHT;
    String defaultAlignment = UIManager.getDefaults().getString("Label.defaultHorizontalAlignment");
    if (defaultAlignment != null) {
        if ("LEFT".equalsIgnoreCase(defaultAlignment)) {
            swingAlign = SwingConstants.LEFT;
        } else if ("RIGHT".equalsIgnoreCase(defaultAlignment)) {
            swingAlign = SwingConstants.RIGHT;
        } else if ("CENTER".equalsIgnoreCase(defaultAlignment)) {
            swingAlign = SwingConstants.CENTER;
        }/*from   www  .ja  v  a2 s  . com*/
    }
    return swingAlign;
}

From source file:Main.java

public static Dimension getPreferredSize(JComponent c, String text, Icon icon, int iconTextGap,
        Rectangle viewRect, Rectangle iconRect, Rectangle textRect) {
    int center = SwingConstants.CENTER;
    return getPreferredSize(c, text, icon, iconTextGap, center, center, center, center, viewRect, iconRect,
            textRect);/*from   w ww  .  ja  v a2 s . co  m*/
}

From source file:JWindowNoTitleBar.java

public JWindowNoTitleBar() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.getContentPane().add(new JLabel("About"), BorderLayout.NORTH);
    window.getContentPane().add(new JLabel("Label", SwingConstants.CENTER), BorderLayout.CENTER);
    JButton b = new JButton("Close");
    window.getContentPane().add(b, BorderLayout.SOUTH);
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            window.setVisible(false);/*from   w  w  w  . j a  v a  2s.  c om*/
        }
    });
    window.pack();
    window.setBounds(50, 50, 200, 200);

    b = new JButton("About...");
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            window.setVisible(true);
        }
    });
    getContentPane().add(b);
    pack();
}