List of usage examples for javax.swing JButton setAlignmentY
@BeanProperty(description = "The preferred vertical alignment of the component.") public void setAlignmentY(float alignmentY)
From source file:AlignY.java
public static void main(String args[]) { JFrame frame = new JFrame("Y Alignment"); JPanel contentPane = (JPanel) frame.getContentPane(); BoxLayout layout = new BoxLayout(contentPane, BoxLayout.X_AXIS); contentPane.setLayout(layout);/*from ww w . j a v a 2s.c o m*/ JButton button = new JButton("0.0"); button.setAlignmentY(Component.TOP_ALIGNMENT); contentPane.add(button); button = new JButton("1.0"); button.setAlignmentY(Component.BOTTOM_ALIGNMENT); contentPane.add(button); button = new JButton("0.5"); button.setAlignmentY(Component.CENTER_ALIGNMENT); contentPane.add(button); frame.setSize(200, 100); frame.show(); }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane editorPane = new JTextPane(); editorPane.setSelectedTextColor(Color.red); // set content as html // editorPane.setContentType("text/html"); editorPane.setText("<p color='#FF0000'>Cool!</p>"); // added <u></u> to underlone button JButton label = new JButton("button"); label.setAlignmentY(0.85f); label.addMouseListener(new MouseAdapter() { @Override//from w ww . ja v a 2 s . c o m public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger() || e.getButton() == MouseEvent.BUTTON1) { JOptionPane.showMessageDialog(null, "Hello!"); } } }); editorPane.insertComponent(label); frame.getContentPane().add(editorPane); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Overlay Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel() { public boolean isOptimizedDrawingEnabled() { return false; }//w w w. ja v a 2 s . co m }; LayoutManager overlay = new OverlayLayout(panel); panel.setLayout(overlay); JButton button = new JButton("Small"); button.setMaximumSize(new Dimension(25, 25)); button.setBackground(Color.white); button.setAlignmentX(0.0f); button.setAlignmentY(0.0f); panel.add(button); button = new JButton("Medium"); button.setMaximumSize(new Dimension(50, 50)); button.setBackground(Color.gray); button.setAlignmentX(0.0f); button.setAlignmentY(0.0f); panel.add(button); button = new JButton("Large"); button.setMaximumSize(new Dimension(100, 100)); button.setBackground(Color.black); button.setAlignmentX(0.0f); button.setAlignmentY(0.0f); panel.add(button); frame.add(panel, BorderLayout.CENTER); frame.setSize(400, 300); frame.setVisible(true); }
From source file:XAxisAlignY.java
private static Container layoutComponents(String title, float alignment) { String labels[] = { "-", "-", "-" }; JPanel container = new JPanel(); container.setBorder(BorderFactory.createTitledBorder(title)); BoxLayout layout = new BoxLayout(container, BoxLayout.X_AXIS); container.setLayout(layout);/* w ww .j av a 2 s .c om*/ for (int i = 0, n = labels.length; i < n; i++) { JButton button = new JButton(labels[i]); button.setAlignmentY(alignment); container.add(button); } return container; }
From source file:XAxisAlignY.java
private static Container makeIt(String title, float alignment) { String labels[] = { "--", "--", "--" }; JPanel container = new JPanel(); container.setBorder(BorderFactory.createTitledBorder(title)); BoxLayout layout = new BoxLayout(container, BoxLayout.X_AXIS); container.setLayout(layout);/*from www . ja va2 s . co m*/ for (int i = 0, n = labels.length; i < n; i++) { JButton button = new JButton(labels[i]); button.setAlignmentY(alignment); container.add(button); } return container; }
From source file:XAxisDiffAlign.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(); int height = getHeight() - insets.top - insets.bottom; int halfHeight = height / 2 + insets.top; g.drawLine(0, halfHeight, width, halfHeight); }//from w w w. j a v a2 s .c o m }; container.setBorder(BorderFactory.createTitledBorder(title)); BoxLayout layout = new BoxLayout(container, BoxLayout.X_AXIS); container.setLayout(layout); JButton button; button = new JButton("0.0"); button.setOpaque(false); button.setAlignmentY(Component.TOP_ALIGNMENT); container.add(button); if (more) { button = new JButton(".25"); button.setOpaque(false); button.setAlignmentY(0.25f); container.add(button); button = new JButton(".5"); button.setOpaque(false); button.setAlignmentY(Component.CENTER_ALIGNMENT); container.add(button); button = new JButton(".75"); button.setOpaque(false); button.setAlignmentY(0.75f); container.add(button); } button = new JButton("1.0"); button.setOpaque(false); button.setAlignmentY(Component.BOTTOM_ALIGNMENT); container.add(button); return container; }
From source file:org.jdal.swing.form.FormUtils.java
/** * Get Default OK Button from LookAndFeel (like JOptionPane) *///from ww w.jav a 2 s.c o m public static JButton newOKButton() { String text = StaticMessageSource.getMessage("Accept"); int mnemonic = getMnemonic("OptionPane.okButtonMnemonic"); JButton b = new JButton(text, OK_ICON); b.setMnemonic(mnemonic); b.setAlignmentX(Container.CENTER_ALIGNMENT); b.setAlignmentY(Container.CENTER_ALIGNMENT); return b; }
From source file:org.jdal.swing.form.FormUtils.java
/** * Get Default Cancel Button from LookAndFeel (like JOptionPane) *//* w w w . jav a 2 s . c o m*/ public static JButton newCancelButton() { String text = StaticMessageSource.getMessage("Cancel"); int mnemonic = getMnemonic("OptionPane.cancelButtonMnemonic"); JButton b = new JButton(text, CANCEL_ICON); b.setMnemonic(mnemonic); b.setAlignmentX(Container.CENTER_ALIGNMENT); b.setAlignmentY(Container.CENTER_ALIGNMENT); return b; }
From source file:ExpenseReport.java
public ExpenseReport() { super("Expense Report"); setSize(570, 200);/* w ww.j a v a2 s. c o m*/ m_data = new ExpenseReportData(this); m_table = new JTable(); m_table.setAutoCreateColumnsFromModel(false); m_table.setModel(m_data); m_table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); for (int k = 0; k < ExpenseReportData.m_columns.length; k++) { TableCellRenderer renderer; if (k == ExpenseReportData.COL_APPROVED) renderer = new CheckCellRenderer(); else { DefaultTableCellRenderer textRenderer = new DefaultTableCellRenderer(); textRenderer.setHorizontalAlignment(ExpenseReportData.m_columns[k].m_alignment); renderer = textRenderer; } TableCellEditor editor; if (k == ExpenseReportData.COL_CATEGORY) editor = new DefaultCellEditor(new JComboBox(ExpenseReportData.CATEGORIES)); else if (k == ExpenseReportData.COL_APPROVED) editor = new DefaultCellEditor(new JCheckBox()); else editor = new DefaultCellEditor(new JTextField()); TableColumn column = new TableColumn(k, ExpenseReportData.m_columns[k].m_width, renderer, editor); m_table.addColumn(column); } JTableHeader header = m_table.getTableHeader(); header.setUpdateTableInRealTime(false); JScrollPane ps = new JScrollPane(); ps.setSize(550, 150); ps.getViewport().add(m_table); getContentPane().add(ps, BorderLayout.CENTER); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); ImageIcon penny = new ImageIcon("penny.gif"); m_title = new JLabel("Total: $", penny, JButton.LEFT); m_title.setForeground(Color.black); m_title.setAlignmentY(0.5f); p.add(m_title); p.add(Box.createHorizontalGlue()); JButton bt = new JButton("Insert before"); bt.setMnemonic('b'); bt.setAlignmentY(0.5f); ActionListener lst = new ActionListener() { public void actionPerformed(ActionEvent e) { int row = m_table.getSelectedRow(); m_data.insert(row); m_table.tableChanged( new TableModelEvent(m_data, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); m_table.repaint(); } }; bt.addActionListener(lst); p.add(bt); bt = new JButton("Insert after"); bt.setMnemonic('a'); bt.setAlignmentY(0.5f); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { int row = m_table.getSelectedRow(); m_data.insert(row + 1); m_table.tableChanged(new TableModelEvent(m_data, row + 1, row + 1, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); m_table.repaint(); } }; bt.addActionListener(lst); p.add(bt); bt = new JButton("Delete row"); bt.setMnemonic('d'); bt.setAlignmentY(0.5f); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { int row = m_table.getSelectedRow(); if (m_data.delete(row)) { m_table.tableChanged(new TableModelEvent(m_data, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); m_table.repaint(); calcTotal(); } } }; bt.addActionListener(lst); p.add(bt); getContentPane().add(p, BorderLayout.SOUTH); calcTotal(); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }
From source file:lisong_mechlab.view.graphs.SustainedDpsGraph.java
/** * Creates and displays the {@link SustainedDpsGraph}. * //from w w w . j ava 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); }