Java Code Examples for javax.swing.JButton#setSize()
The following examples show how to use
javax.swing.JButton#setSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleForm.java From java-1-class-demos with MIT License | 7 votes |
public void addBtn(String name) { button = new JButton(name); button.setVisible(true); button.setSize(100, 50); button.setLocation(50, 25); this.add(button); }
Example 2
Source File: SimpleForm.java From java-1-class-demos with MIT License | 7 votes |
public void addBtn(String name) { button = new JButton(name); button.setVisible(true); button.setSize(100, 50); button.setLocation(50, 25); this.add(button); }
Example 3
Source File: MainView.java From HiJson with Apache License 2.0 | 7 votes |
private void codeChangeAction(){ javax.swing.JDialog dlg = new javax.swing.JDialog(getFrame()); dlg.setTitle(resourceMap.getString("menuItemCode.text")); dlg.setSize(500, 350); dlg.setMinimumSize(new Dimension(500, 350)); JSplitPane spiltPane2 = new JSplitPane(); spiltPane2.setDividerLocation(150); spiltPane2.setOrientation(JSplitPane.VERTICAL_SPLIT); final JTextArea textAreaSrc = new JTextArea(); final JTextArea textAreaDest = new JTextArea(); textAreaSrc.setLineWrap(true); textAreaDest.setLineWrap(true); spiltPane2.setTopComponent(new JScrollPane(textAreaSrc)); spiltPane2.setBottomComponent(new JScrollPane(textAreaDest)); JButton btnOK = new JButton("转换"); btnOK.setSize(50, 25); java.awt.Container pane = dlg.getContentPane(); BorderLayout layout = new BorderLayout(); //layout.addLayoutComponent(spiltPane, BorderLayout.CENTER); // layout.addLayoutComponent(btnOK, BorderLayout.SOUTH); pane.setLayout(layout); pane.add(spiltPane2, BorderLayout.CENTER); pane.add(btnOK, BorderLayout.SOUTH); btnOK.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String str = textAreaSrc.getText(); str = StringEscapeUtils.unescapeJava(str); textAreaDest.setText(str); } }); MainApp.getApplication().show(dlg); }
Example 4
Source File: ClosableTab.java From incubator-iotdb with Apache License 2.0 | 6 votes |
ClosableTab(String name, TabCloseCallBack closeCallBack) { setName(name); setLayout(null); closeTabButton = new JButton("Close"); closeTabButton.setLocation(720, 5); closeTabButton.setSize(new Dimension(70, 30)); closeTabButton.setFont(closeTabButton.getFont().deriveFont(10.0f)); add(closeTabButton); closeTabButton.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { closeCallBack.call(name); } }); }
Example 5
Source File: bug6190373.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static void slam(final boolean lock) { JButton button = new JButton("HI"); button.setSize(100, 100); BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); for (int i = 0; i < LOOP_COUNT; i++) { Graphics g = image.getGraphics(); if (lock) { synchronized (button.getTreeLock()) { button.paint(g); } } else { button.paint(g); } g.dispose(); } }
Example 6
Source File: ControlPanel.java From testing-cin with MIT License | 5 votes |
/** * Creates an action button. * * @param action * The action. * * @return The button. */ private JButton createActionButton(Action action) { String label = action.getName(); JButton button = new JButton(label); button.setMnemonic(label.charAt(0)); button.setSize(100, 30); button.addActionListener(this); return button; }
Example 7
Source File: SwingBQPMonitor.java From swift-k with Apache License 2.0 | 5 votes |
private JButton addButton(int x, int y, String t) { JButton b = new JButton(); b.setText(t); b.setLocation(x, y); b.setSize(44, 24); this.add(b); b.addActionListener(this); return b; }
Example 8
Source File: ColorEditor.java From jpexs-decompiler with GNU General Public License v3.0 | 5 votes |
public ColorEditor(String fieldName, Object obj, Field field, int index, Class<?> type) { this.obj = obj; this.field = field; this.index = index; this.type = type; this.fieldName = fieldName; setLayout(new FlowLayout()); buttonChange = new JButton("") { @Override protected void paintComponent(Graphics g) { g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); super.paintBorder(g); } }; buttonChange.setToolTipText(AppStrings.translate("button.selectcolor.hint")); buttonChange.setCursor(new Cursor(Cursor.HAND_CURSOR)); buttonChange.addActionListener(this); buttonChange.setBorderPainted(true); buttonChange.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); Dimension colorDim = new Dimension(16, 16); buttonChange.setSize(colorDim); buttonChange.setPreferredSize(colorDim); add(buttonChange); reset(); }
Example 9
Source File: ImageRenderFunction.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Create a image according to the current state, simple and silly ... * * @param event the report event. */ public void pageStarted(final ReportEvent event) { final BufferedImage image = new BufferedImage(150, 50, BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = image.createGraphics(); final JButton bt = new JButton("A Button"); bt.setSize(90, 20); final JRadioButton radio = new JRadioButton("A radio button"); radio.setSize(100, 20); g2.setColor(Color.darkGray); bt.paint(g2); g2.setColor(Color.blue); g2.setTransform(AffineTransform.getTranslateInstance(20, 20)); radio.paint(g2); g2.setTransform(AffineTransform.getTranslateInstance(0, 0)); g2.setPaint(Color.green); g2.setFont(new Font("Serif", Font.PLAIN, 10)); g2.drawString("You are viewing a graphics of JFreeReport on index " + event.getState().getCurrentRow(), 10, 10); g2.dispose(); try { functionValue = new DefaultImageReference(image); } catch (IOException e) { functionValue = null; } }
Example 10
Source File: SwingUtil.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
/** * Create swing button from navigation button. * * @param navigationButton the navigation button * @param iconSize the icon size (in case it is 0 default icon size will be used) * @param specialCallback the special callback * @return the swing button */ public static JButton createSwingButton( @Nonnull final NavigationButton navigationButton, int iconSize, @Nullable final BiConsumer<NavigationButton, JButton> specialCallback) { final BufferedImage scaledImage = iconSize > 0 ? ImageUtil.resizeImage(navigationButton.getIcon(), iconSize, iconSize) : navigationButton.getIcon(); final JButton button = new JButton(); button.setSize(scaledImage.getWidth(), scaledImage.getHeight()); button.setToolTipText(navigationButton.getTooltip()); button.setIcon(new ImageIcon(scaledImage)); button.putClientProperty(SubstanceSynapse.FLAT_LOOK, Boolean.TRUE); button.setFocusable(false); button.addActionListener(e -> { if (specialCallback != null) { specialCallback.accept(navigationButton, button); } if (navigationButton.getOnClick() != null) { navigationButton.getOnClick().run(); } }); if (navigationButton.getPopup() != null) { final JPopupMenu popupMenu = new JPopupMenu(); navigationButton.getPopup().forEach((name, callback) -> { final JMenuItem menuItem = new JMenuItem(name); menuItem.addActionListener((e) -> callback.run()); popupMenu.add(menuItem); }); button.setComponentPopupMenu(popupMenu); } navigationButton.setOnSelect(button::doClick); return button; }
Example 11
Source File: BoardNewDialog.java From megamek with GNU General Public License v2.0 | 4 votes |
BoardNewDialog(JFrame frame) { super(frame, Messages.getString("BoardEditor.SetDimensions"), true); //$NON-NLS-1$ xvalue = 0; yvalue = 0; labWidth = new JLabel( Messages.getString("BoardEditor.labWidth"), SwingConstants.RIGHT); //$NON-NLS-1$ labHeight = new JLabel( Messages.getString("BoardEditor.labHeight"), SwingConstants.RIGHT); //$NON-NLS-1$ texWidth = new JTextField("16", 2); //$NON-NLS-1$ texHeight = new JTextField("17", 2); //$NON-NLS-1$ butOkay = new JButton(Messages.getString("Okay")); //$NON-NLS-1$ butOkay.setActionCommand("done"); //$NON-NLS-1$ butOkay.addActionListener(this); butOkay.setSize(80, 24); butCancel = new JButton(Messages.getString("Cancel")); //$NON-NLS-1$ butCancel.setActionCommand("cancel"); //$NON-NLS-1$ butCancel.addActionListener(this); butCancel.setSize(80, 24); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); getContentPane().setLayout(gridbag); c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; c.insets = new Insets(5, 5, 1, 1); gridbag.setConstraints(labWidth, c); getContentPane().add(labWidth); c.gridwidth = GridBagConstraints.REMAINDER; gridbag.setConstraints(texWidth, c); getContentPane().add(texWidth); c.gridwidth = GridBagConstraints.RELATIVE; gridbag.setConstraints(labHeight, c); getContentPane().add(labHeight); c.gridwidth = GridBagConstraints.REMAINDER; gridbag.setConstraints(texHeight, c); getContentPane().add(texHeight); c.ipadx = 20; c.ipady = 5; c.gridwidth = GridBagConstraints.RELATIVE; gridbag.setConstraints(butOkay, c); getContentPane().add(butOkay); c.gridwidth = GridBagConstraints.REMAINDER; gridbag.setConstraints(butCancel, c); getContentPane().add(butCancel); pack(); setResizable(false); setLocation(frame.getLocation().x + frame.getSize().width / 2 - getSize().width / 2, frame.getLocation().y + frame.getSize().height / 2 - getSize().height / 2); }
Example 12
Source File: ExportJar.java From bytecode-viewer with GNU General Public License v3.0 | 4 votes |
public ExportJar(final String jarPath) { setSize(new Dimension(250, 277)); setResizable(false); setTitle("Save As Jar.."); JButton btnNewButton = new JButton("Save As Jar.."); btnNewButton.setMaximumSize(new Dimension(999, 23)); btnNewButton.setMinimumSize(new Dimension(999, 23)); btnNewButton.setSize(new Dimension(999, 0)); getContentPane().setLayout( new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); JScrollPane scrollPane = new JScrollPane(); getContentPane().add(scrollPane); JLabel lblMetainfmanifestmf = new JLabel("META-INF/MANIFEST.MF:"); scrollPane.setColumnHeaderView(lblMetainfmanifestmf); final JTextArea mani = new JTextArea(); mani.setText("Manifest-Version: 1.0\r\nClass-Path: .\r\nMain-Class: "); scrollPane.setViewportView(mani); getContentPane().add(btnNewButton); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { BytecodeViewer.viewer.setIcon(true); Thread t = new Thread() { @Override public void run() { JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), jarPath, mani.getText()); BytecodeViewer.viewer.setIcon(false); } }; t.start(); dispose(); } }); this.setLocationRelativeTo(null); }
Example 13
Source File: CloseTabPaneUI.java From iBioSim with Apache License 2.0 | 3 votes |
public CloseTabPaneUI(Gui biosim) { super(); this.biosim = biosim; closeImgB = new BufferedImage(BUTTONSIZE, BUTTONSIZE, BufferedImage.TYPE_4BYTE_ABGR); closeImgI = new BufferedImage(BUTTONSIZE, BUTTONSIZE, BufferedImage.TYPE_4BYTE_ABGR); closeB = new JButton(); closeB.setIcon(ResourceManager.getImageIcon("close.gif")); closeB.setSize(BUTTONSIZE, BUTTONSIZE); //WindowsIconFactory.createFrameCloseIcon().paintIcon(closeB, closeImgI.createGraphics(), 0, 0); actionPopupMenu = new JPopupMenu(); closeItem = new JMenuItem("Close"); closeItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ((CloseAndMaxTabbedPane) tabPane).fireCloseTabEvent(null, tabPane.getSelectedIndex()); } }); setPopupMenu(); }