List of usage examples for javax.swing JButton setVerticalAlignment
@BeanProperty(visualUpdate = true, enumerationValues = { "SwingConstants.TOP", "SwingConstants.CENTER", "SwingConstants.BOTTOM" }, description = "The vertical alignment of the icon and text.") public void setVerticalAlignment(int alignment)
From source file:MovingIconTest.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); JButton b; Icon icon = new PieIcon(Color.red); b = new JButton("Default", icon); contentPane.add(b, BorderLayout.NORTH); b = new JButton("Text Left", icon); b.setHorizontalTextPosition(JButton.LEFT); contentPane.add(b, BorderLayout.SOUTH); b = new JButton("Text Up", icon); b.setHorizontalTextPosition(JButton.CENTER); b.setVerticalTextPosition(JButton.TOP); contentPane.add(b, BorderLayout.EAST); b = new JButton("Text Down", icon); b.setHorizontalTextPosition(JButton.CENTER); b.setVerticalTextPosition(JButton.BOTTOM); contentPane.add(b, BorderLayout.WEST); b = new JButton("Align Bottom Left", icon); b.setHorizontalAlignment(JButton.LEFT); b.setVerticalAlignment(JButton.BOTTOM); contentPane.add(b, BorderLayout.CENTER); frame.setSize(300, 200);//ww w . j a va2 s .co m frame.show(); }
From source file:MainClass.java
MainClass(String title) { super(title); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton jb = new JButton("Ok", new ImageIcon("bullet.gif")); jb.setHorizontalAlignment(SwingConstants.LEFT); jb.setMnemonic('O'); getContentPane().add(jb, BorderLayout.CENTER); jb = new JButton("<html><i>Cancel</i></html>"); jb.setVerticalAlignment(SwingConstants.BOTTOM); jb.setDefaultCapable(true);/*from ww w . j a va 2 s.com*/ getContentPane().add(jb, BorderLayout.EAST); getRootPane().setDefaultButton(jb); setSize(200, 100); setVisible(true); }
From source file:com.smart.aqimonitor.client.AqiMonitor.java
/** * Create the frame./* w w w . ja v a 2 s .c om*/ */ public AqiMonitor() { refSelf = this; setPreferredSize(new Dimension(640, 480)); setTitle("\u7A7A\u6C14\u8D28\u91CF\u76D1\u6D4B"); setIconImage(Toolkit.getDefaultToolkit() .getImage(AqiMonitor.class.getResource("/lombok/installer/eclipse/STS.png"))); setMinimumSize(new Dimension(640, 480)); setMaximumSize(new Dimension(1024, 768)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 636, 412); contentPane = new JPanel(); contentPane.setPreferredSize(new Dimension(640, 480)); contentPane.setMinimumSize(new Dimension(640, 480)); contentPane.setMaximumSize(new Dimension(1024, 768)); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); JPanel mainPanel = new JPanel(); contentPane.add(mainPanel, BorderLayout.CENTER); mainPanel.setLayout(new BorderLayout(0, 0)); JPanel contentPanel = new JPanel(); mainPanel.add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(new BorderLayout(0, 0)); JScrollPane scrollPane = new JScrollPane(); scrollPane .setViewportBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null)); contentPanel.add(scrollPane, BorderLayout.CENTER); textPane = new AqiTextPane(); textPane.addInputMethodListener(new InputMethodListener() { public void caretPositionChanged(InputMethodEvent event) { } public void inputMethodTextChanged(InputMethodEvent event) { textPane.setCaretPosition(document.getLength() + 1); } }); textPane.setEditable(false); textPane.setOpaque(false); textPane.setForeground(Color.BLACK); scrollPane.setViewportView(textPane); document = textPane.getStyledDocument(); document.addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { changedUpdate(e); } @Override public void insertUpdate(DocumentEvent e) { changedUpdate(e); } @Override public void changedUpdate(DocumentEvent e) { if (e.getDocument() == document) { textPane.setCaretPosition(document.getLength()); } } }); JPanel buttonPanel = new JPanel(); contentPane.add(buttonPanel, BorderLayout.SOUTH); buttonPanel.setLayout(new BorderLayout(0, 0)); JLabel lblTipsLabel = new JLabel( "Tips\uFF1A\u6587\u4EF6\u4FDD\u5B58\u683C\u5F0Fcsv\u53EF\u7528Excel\u6253\u5F00"); lblTipsLabel.setForeground(Color.BLUE); buttonPanel.add(lblTipsLabel, BorderLayout.WEST); JPanel panel = new JPanel(); buttonPanel.add(panel, BorderLayout.CENTER); panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); JButton btnRetrieve = new JButton("\u624B\u52A8\u83B7\u53D6\u6570\u636E"); panel.add(btnRetrieve); btnRetrieve.setVerticalAlignment(SwingConstants.BOTTOM); JButton btnNewButton = new JButton("\u5173\u4E8E"); btnNewButton.setToolTipText("\u5173\u4E8E"); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JTextArea textArea = new JTextArea( "\n csv\n\n smartstudio@foxmail.com"); textArea.setColumns(35); textArea.setRows(6); textArea.setLineWrap(true);// textArea.setEditable(false);// textArea.setOpaque(false); JOptionPane.showMessageDialog(contentPane, textArea, "", JOptionPane.PLAIN_MESSAGE); } }); JButton btnSetting = new JButton("\u8BBE\u7F6E"); btnSetting.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Point parentPos = refSelf.getLocation(); AqiSettingDialog settingDialog = new AqiSettingDialog(refSelf, pm25InDetailJob.getAqiParser()); settingDialog.setModal(true); settingDialog.setLocation(parentPos.x + 100, parentPos.y + 150); settingDialog.init(); settingDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); settingDialog.setVisible(true); } }); JButton btnExportDir = new JButton("\u67E5\u770B\u6570\u636E"); btnExportDir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { String[] cmd = new String[5]; String filePath = pm25InDetailJob.getAqiParser().getFilePath(); File file = new File(filePath); if (!file.exists()) { FileUtil.makeDir(file); } if (!file.isDirectory()) { JOptionPane.showMessageDialog(contentPane, "", "", JOptionPane.ERROR_MESSAGE); return; } cmd[0] = "cmd"; cmd[1] = "/c"; cmd[2] = "start"; cmd[3] = " "; cmd[4] = pm25InDetailJob.getAqiParser().getFilePath(); Runtime.getRuntime().exec(cmd); } catch (IOException ex) { ex.printStackTrace(); } } }); panel.add(btnExportDir); panel.add(btnSetting); panel.add(btnNewButton); btnRetrieve.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (!isRetrieving) { isRetrieving = true; Thread firstRun = new Thread(new Runnable() { @Override public void run() { pm25InDetailJob.refresh(); isRetrieving = false; } }); firstRun.start(); } } }); init(); }