/** * Creates a button pane in which the given buttons are neatly aligned with proper spacings. * * @param aButtons the buttons to add to the created button pane, will be added in the given * order. * @return the button pane, never <code>null</code>. */ public static JComponent createButtonPane(final JButton... aButtons) { if ((aButtons == null) || (aButtons.length < 1)) { throw new IllegalArgumentException("Need at least one button!"); } final JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.setBorder( BorderFactory.createEmptyBorder( BUTTONS_PADDING_TOP, BUTTONS_PADDING_LEFT, BUTTONS_PADDING_BOTTOM, BUTTONS_PADDING_RIGHT)); buttonPane.add(Box.createHorizontalGlue()); // we want equally sized buttons, so we are recording preferred sizes while // adding the buttons and set them to the maximum afterwards... int width = 1; int height = 1; for (JButton button : aButtons) { width = Math.max(width, button.getPreferredSize().width); height = Math.max(height, button.getPreferredSize().height); buttonPane.add(Box.createHorizontalStrut(BUTTONS_SPACING_DEFAULT)); buttonPane.add(button); } buttonPane.add(Box.createHorizontalStrut(BUTTONS_SPACING_DEFAULT)); final Dimension newDims = new Dimension(width, height); // everything added; let's set all sizes for (final JButton button : aButtons) { button.setPreferredSize(newDims); } return buttonPane; }
/** * Standard constructor: it needs the parent frame. * * @param parent the dialog's parent */ public DialogPrint(JFrame parent) { super(400, 350, parent, Globals.messages.getString("Print_dlg"), true); addComponentListener(this); export = false; // Ensure that under MacOSX >= 10.5 Leopard, this dialog will appear // as a document modal sheet getRootPane().putClientProperty("apple.awt.documentModalSheet", Boolean.TRUE); GridBagLayout bgl = new GridBagLayout(); GridBagConstraints constraints = new GridBagConstraints(); Container contentPane = getContentPane(); contentPane.setLayout(bgl); constraints.insets.right = 30; JLabel empty = new JLabel(" "); constraints.weightx = 100; constraints.weighty = 100; constraints.gridx = 0; constraints.gridy = 0; constraints.gridwidth = 1; constraints.gridheight = 1; contentPane.add(empty, constraints); // Add " " label JLabel empty1 = new JLabel(" "); constraints.weightx = 100; constraints.weighty = 100; constraints.gridx = 3; constraints.gridy = 0; constraints.gridwidth = 1; constraints.gridheight = 1; contentPane.add(empty1, constraints); // Add " " label mirror_CB = new JCheckBox(Globals.messages.getString("Mirror")); constraints.gridx = 1; constraints.gridy = 0; constraints.gridwidth = 2; constraints.gridheight = 1; constraints.anchor = GridBagConstraints.WEST; contentPane.add(mirror_CB, constraints); // Add Print Mirror cb fit_CB = new JCheckBox(Globals.messages.getString("FitPage")); constraints.gridx = 1; constraints.gridy = 1; constraints.gridwidth = 2; constraints.gridheight = 1; constraints.anchor = GridBagConstraints.WEST; contentPane.add(fit_CB, constraints); // Add Fit to page cb bw_CB = new JCheckBox(Globals.messages.getString("B_W")); constraints.gridx = 1; constraints.gridy = 2; constraints.gridwidth = 2; constraints.gridheight = 1; constraints.anchor = GridBagConstraints.WEST; contentPane.add(bw_CB, constraints); // Add BlackWhite cb landscape_CB = new JCheckBox(Globals.messages.getString("Landscape")); constraints.gridx = 1; constraints.gridy = 3; constraints.gridwidth = 2; constraints.gridheight = 1; constraints.anchor = GridBagConstraints.WEST; contentPane.add(landscape_CB, constraints); // Add landscape cb // Put the OK and Cancel buttons and make them active. JButton ok = new JButton(Globals.messages.getString("Ok_btn")); JButton cancel = new JButton(Globals.messages.getString("Cancel_btn")); constraints.gridx = 0; constraints.gridy = 4; constraints.gridwidth = 4; constraints.gridheight = 1; constraints.anchor = GridBagConstraints.EAST; // Put the OK and Cancel buttons and make them active. Box b = Box.createHorizontalBox(); b.add(Box.createHorizontalGlue()); ok.setPreferredSize(cancel.getPreferredSize()); if (Globals.okCancelWinOrder) { b.add(ok); b.add(Box.createHorizontalStrut(12)); b.add(cancel); } else { b.add(cancel); b.add(Box.createHorizontalStrut(12)); b.add(ok); } ok.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { export = true; setVisible(false); } }); cancel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { setVisible(false); } }); // Here is an action in which the dialog is closed AbstractAction cancelAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { setVisible(false); } }; contentPane.add(b, constraints); // Add OK/cancel dialog DialogUtil.addCancelEscape(this, cancelAction); pack(); DialogUtil.center(this); getRootPane().setDefaultButton(ok); }
void createFrame() { /* see Preferences.java */ int GUI_BIG = 13; int GUI_BETWEEN = 10; int GUI_SMALL = 6; int FIELD_SIZE = 30; int left = GUI_BIG; int top = GUI_BIG; int right = 0; Dimension d; frame = new JFrame("Directives Editor"); Container pane = frame.getContentPane(); pane.setLayout(null); JLabel label = new JLabel("Click here to read about directives."); label.addMouseListener( new MouseListener() { public void mouseClicked(MouseEvent e) { Base.openURL("http://processingjs.org/reference/pjs%20directive"); } public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} }); pane.add(label); d = label.getPreferredSize(); label.setBounds(left, top, d.width, d.height); top += d.height + GUI_BETWEEN + GUI_BETWEEN; // CRISP crispBox = new JCheckBox("\"crisp\": disable antialiasing for line(), triangle() and rect()"); pane.add(crispBox); d = crispBox.getPreferredSize(); crispBox.setBounds(left, top, d.width + 10, d.height); right = Math.max(right, left + d.width); top += d.height + GUI_BETWEEN; // FONTS label = new JLabel("\"font\": to load (comma separated)"); pane.add(label); d = label.getPreferredSize(); label.setBounds(left, top, d.width, d.height); top += d.height + GUI_SMALL; fontField = new JTextField(FIELD_SIZE); pane.add(fontField); d = fontField.getPreferredSize(); fontField.setBounds(left, top, d.width, d.height); JButton button = new JButton("scan"); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { handleScanFonts(); } }); pane.add(button); Dimension d2 = button.getPreferredSize(); button.setBounds(left + d.width + GUI_SMALL, top, d2.width, d2.height); right = Math.max(right, left + d.width + GUI_SMALL + d2.width); top += d.height + GUI_BETWEEN; // GLOBAL_KEY_EVENTS globalKeyEventsBox = new JCheckBox("\"globalKeyEvents\": receive global key events"); pane.add(globalKeyEventsBox); d = globalKeyEventsBox.getPreferredSize(); globalKeyEventsBox.setBounds(left, top, d.width + 10, d.height); right = Math.max(right, left + d.width); top += d.height + GUI_BETWEEN; // PAUSE_ON_BLUR pauseOnBlurBox = new JCheckBox("\"pauseOnBlur\": pause if applet loses focus"); pane.add(pauseOnBlurBox); d = pauseOnBlurBox.getPreferredSize(); pauseOnBlurBox.setBounds(left, top, d.width + 10, d.height); right = Math.max(right, left + d.width); top += d.height + GUI_BETWEEN; // PRELOAD images label = new JLabel("\"preload\": images (comma separated)"); pane.add(label); d = label.getPreferredSize(); label.setBounds(left, top, d.width, d.height); top += d.height + GUI_SMALL; preloadField = new JTextField(FIELD_SIZE); pane.add(preloadField); d = preloadField.getPreferredSize(); preloadField.setBounds(left, top, d.width, d.height); button = new JButton("scan"); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { handleScanImages(); } }); pane.add(button); d2 = button.getPreferredSize(); button.setBounds(left + d.width + GUI_SMALL, top, d2.width, d2.height); right = Math.max(right, left + d.width + GUI_SMALL + d2.width); top += d.height + GUI_BETWEEN; // TRANSPARENT /*transparentBox = new JCheckBox("\"transparent\": set applet background to be transparent"); pane.add(transparentBox); d = transparentBox.getPreferredSize(); transparentBox.setBounds(left, top, d.width + 10, d.height); right = Math.max(right, left + d.width); top += d.height + GUI_BETWEEN;*/ // APPLY / OK button = new JButton("OK"); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { applyDirectives(); hide(); } }); pane.add(button); d2 = button.getPreferredSize(); int BUTTON_HEIGHT = d2.height; int BUTTON_WIDTH = 80; int h = right - (BUTTON_WIDTH + GUI_SMALL + BUTTON_WIDTH); button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT); h += BUTTON_WIDTH + GUI_SMALL; button = new JButton("Cancel"); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { hide(); } }); pane.add(button); button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT); top += BUTTON_HEIGHT + GUI_BETWEEN; // frame.getContentPane().add(box); frame.pack(); Insets insets = frame.getInsets(); frame.setSize( right + GUI_BIG + insets.left + insets.right, top + GUI_SMALL + insets.top + insets.bottom); // frame.setResizable(false); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { frame.setVisible(false); } }); Toolkit.registerWindowCloseKeys( frame.getRootPane(), new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { frame.setVisible(false); } }); Toolkit.setIcon(frame); }
public SketchProperties(Editor e, Sketch s) { super(); editor = e; sketch = s; fields = new HashMap<String, JComponent>(); this.setPreferredSize(new Dimension(500, 400)); this.setMinimumSize(new Dimension(500, 400)); this.setMaximumSize(new Dimension(500, 400)); this.setSize(new Dimension(500, 400)); Point eLoc = editor.getLocation(); int x = eLoc.x; int y = eLoc.y; Dimension eSize = editor.getSize(); int w = eSize.width; int h = eSize.height; int cx = x + (w / 2); int cy = y + (h / 2); this.setLocation(new Point(cx - 250, cy - 200)); this.setModal(true); outer = new JPanel(new BorderLayout()); outer.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); this.add(outer); win = new JPanel(); win.setLayout(new BorderLayout()); outer.add(win, BorderLayout.CENTER); buttonBar = new JPanel(new FlowLayout(FlowLayout.RIGHT)); saveButton = new JButton("OK"); saveButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { save(); SketchProperties.this.dispose(); } }); cancelButton = new JButton("Cancel"); cancelButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { SketchProperties.this.dispose(); } }); buttonBar.add(saveButton); buttonBar.add(cancelButton); win.add(buttonBar, BorderLayout.SOUTH); tabs = new JTabbedPane(); overviewPane = new JPanel(); overviewPane.setLayout(new BoxLayout(overviewPane, BoxLayout.PAGE_AXIS)); overviewPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); addTextField(overviewPane, "author", "Sketch author:"); addTextArea(overviewPane, "summary", "Summary:"); addTextArea(overviewPane, "license", "Copyright / License:"); tabs.add("Overview", overviewPane); objectsPane = new JPanel(); objectsPane.setLayout(new BoxLayout(objectsPane, BoxLayout.PAGE_AXIS)); objectsPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); addTextField(objectsPane, "board", "Board:"); addTextField(objectsPane, "core", "Core:"); addTextField(objectsPane, "compiler", "Compiler:"); addTextField(objectsPane, "port", "Serial port:"); addTextField(objectsPane, "programmer", "Programmer:"); JButton setDef = new JButton("Set to current IDE values"); setDef.setMaximumSize(setDef.getPreferredSize()); setDef.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { setObjectValues(); } }); objectsPane.add(Box.createVerticalGlue()); objectsPane.add(setDef); tabs.add("Objects", objectsPane); win.add(tabs, BorderLayout.CENTER); this.setTitle("Sketch Properties"); this.pack(); this.setVisible(true); }
public LoginPanel(Image img, ActionListener listener) { super(null); this.listener = listener; if (img == null) { InputStream inData = getClass().getResourceAsStream("/resources/background.gif"); BufferedImage back = null; if (inData != null) try { back = ImageIO.read(inData); } catch (IOException e) { loger.finest("LoginPanel class can't get the background image"); } this.background = back; } setLayout(null); JPanel logingPanel = new JPanel(); loginTitle = new JLabel("Autentificare"); logingPanel.setSize(250, 150); logingPanel.setBorder(new javax.swing.border.LineBorder(Color.black, 2)); logingPanel.setLayout(null); loginTitle.setBounds(3, 0, logingPanel.getWidth(), 20); logingPanel.add(loginTitle); JLabel loginUser = new JLabel("Utilizator"); loginUser.setBounds( 80 - loginUser.getPreferredSize().width, 40, loginUser.getPreferredSize().width, loginUser.getPreferredSize().height); logingPanel.add(loginUser); user = new JTextField(10); user.setBounds(85, 40, user.getPreferredSize().width, user.getPreferredSize().height); // user.setText("test"); // loginUser.setLabelFor(user); logingPanel.add(user); JLabel loginPass = new JLabel("Parola"); loginPass.setBounds( 80 - loginPass.getPreferredSize().width, 80, loginPass.getPreferredSize().width, loginPass.getPreferredSize().height); logingPanel.add(loginPass); // JTextField pass = new JTextField(10); pass = new JPasswordField(10); pass.setBounds(85, 80, pass.getPreferredSize().width, pass.getPreferredSize().height); pass.addKeyListener(this); // pass.setText("test"); // loginUser.setLabelFor(user); logingPanel.add(pass); JButton loginButton = new JButton("Start"); loginButton.setActionCommand("LOGIN"); loginButton.setBounds( 60, 110, loginButton.getPreferredSize().width, loginButton.getPreferredSize().height); // loginButton.setOpaque(false); loginButton.setFocusPainted(false); // loginButton.setContentAreaFilled(false); // loginButton.setBorderPainted(false); loginButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); loginButton.addActionListener(listener); logingPanel.add(loginButton); add(logingPanel); }