List of usage examples for javax.swing SwingConstants CENTER
int CENTER
To view the source code for javax.swing SwingConstants CENTER.
Click Source Link
From source file:Main.java
public Main() { super("JLabel Demo"); setSize(600, 100);/*from w w w .j a v a 2s .c o m*/ JPanel content = new JPanel(new GridLayout(1, 4, 4, 4)); JLabel label = new JLabel("Java2s"); label.setBackground(Color.white); content.add(label); label = new JLabel("Java2s", SwingConstants.CENTER); label.setOpaque(true); label.setBackground(Color.white); content.add(label); label = new JLabel("Java2s"); label.setFont(new Font("Helvetica", Font.BOLD, 18)); label.setOpaque(true); label.setBackground(Color.white); content.add(label); ImageIcon image = new ImageIcon("java2sLogo.gif"); label = new JLabel("Java2s", image, SwingConstants.RIGHT); label.setVerticalTextPosition(SwingConstants.TOP); label.setOpaque(true); label.setBackground(Color.white); content.add(label); getContentPane().add(content); setVisible(true); }
From source file:LabelDemo.java
public LabelDemo() { super("JLabel Demo"); setSize(600, 100);// ww w. j a va2 s.com JPanel content = new JPanel(new GridLayout(1, 4, 4, 4)); JLabel label = new JLabel("Java2s"); label.setBackground(Color.white); content.add(label); label = new JLabel("Java2s", SwingConstants.CENTER); label.setOpaque(true); label.setBackground(Color.white); content.add(label); label = new JLabel("Java2s"); label.setFont(new Font("Helvetica", Font.BOLD, 18)); label.setOpaque(true); label.setBackground(Color.white); content.add(label); ImageIcon image = new ImageIcon("java2sLogo.gif"); label = new JLabel("Java2s", image, SwingConstants.RIGHT); label.setVerticalTextPosition(SwingConstants.TOP); label.setOpaque(true); label.setBackground(Color.white); content.add(label); getContentPane().add(content); setVisible(true); }
From source file:ImageLabelExample.java
protected static JLabel makeLabel(int vert, int horiz) { JLabel l = new JLabel("Smile", icon, SwingConstants.CENTER); l.setVerticalTextPosition(vert);/* w w w . j ava 2 s .co m*/ l.setHorizontalTextPosition(horiz); l.setBorder(BorderFactory.createLineBorder(Color.black)); return l; }
From source file:Main.java
public Main() { GridLayout g = new GridLayout(3, 3); pan = new JPanel(g); pan.add(new JButton("1")); pan.add(new JButton("2")); pan.add(new JButton("3")); pan.add(new JButton("4")); pan.add(new JButton("5")); pan.add(new JButton("6")); pan.add(new JButton("7")); pan.add(new JButton("8")); pan.add(new JButton("9")); JLabel l = new JLabel("grid layout"); l.setHorizontalAlignment(SwingConstants.CENTER); setLayout(new BorderLayout()); add(l, BorderLayout.NORTH);//ww w .j a va 2 s . co m add(pan, BorderLayout.CENTER); setSize(1000, 500); setVisible(true); }
From source file:Main.java
public Main() { mainPanel.setPreferredSize(new Dimension(WIDTH, HEIGHT)); mainPanel.setLayout(null);/*w w w . ja v a2 s.c o m*/ MyMouseAdapter myMouseAdapter = new MyMouseAdapter(); for (int i = 0; i < LABEL_STRINGS.length; i++) { JLabel label = new JLabel(LABEL_STRINGS[i], SwingConstants.CENTER); label.setSize(new Dimension(LBL_WIDTH, LBL_HEIGHT)); label.setOpaque(true); Random random = new Random(); label.setLocation(random.nextInt(WIDTH - LBL_WIDTH), random.nextInt(HEIGHT - LBL_HEIGHT)); label.setBackground( new Color(150 + random.nextInt(105), 150 + random.nextInt(105), 150 + random.nextInt(105))); label.addMouseListener(myMouseAdapter); label.addMouseMotionListener(myMouseAdapter); mainPanel.add(label); } }
From source file:Main.java
private JPanel createGridPanel() { int rows = 5; int cols = 5; JPanel gridPanel = new JPanel(new GridLayout(rows, cols)); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { JLabel label = new JLabel(String.format("[%d, %d]", i, j), SwingConstants.CENTER); label.setBorder(BorderFactory.createEtchedBorder()); gridPanel.add(label);// w w w. j a v a 2s . c om } } return gridPanel; }
From source file:Main.java
public Main() { frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); iconLabel = new JLabel("Please select an image."); iconLabel.setHorizontalAlignment(SwingConstants.CENTER); fileChooser = new JFileChooser(); frame.add(iconLabel, BorderLayout.CENTER); frame.add(new JButton(new SelectImageAction("Select Image...")), BorderLayout.SOUTH); frame.setBounds(16, 16, 640, 480);/*from w ww . j av a 2 s .c om*/ frame.setVisible(true); }
From source file:NotHelloWorldApplet.java
public void init() { EventQueue.invokeLater(new Runnable() {/*w ww.j a va 2 s. c o m*/ public void run() { JLabel label = new JLabel("Not a Hello, World applet", SwingConstants.CENTER); add(label); } }); }
From source file:Main.java
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { JTextField editor = (JTextField) super.getTableCellEditorComponent(table, value, isSelected, row, column); if (value != null) editor.setText(value.toString()); if (column == 0) { editor.setHorizontalAlignment(SwingConstants.CENTER); editor.setFont(new Font("Serif", Font.BOLD, 14)); } else {/*from w ww. j a v a 2 s. co m*/ editor.setHorizontalAlignment(SwingConstants.RIGHT); editor.setFont(new Font("Serif", Font.ITALIC, 12)); } return editor; }
From source file:com.opendoorlogistics.studio.tables.grid.HeaderCellRenderer.java
/** * /*from w w w . j a va2s . co m*/ */ protected void initLabel(JLabel label) { label.setOpaque(true); label.setHorizontalAlignment(SwingConstants.CENTER); label.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); }