List of usage examples for javax.swing BorderFactory createCompoundBorder
public static CompoundBorder createCompoundBorder(Border outsideBorder, Border insideBorder)
From source file:org.owasp.jbrofuzz.fuzz.ui.FuzzingPanel.java
public static JPanel createScrollingPanel(String title, JTextPane textPane) { // The request panel final JPanel panel = new JPanel(new BorderLayout()); // The message scroll pane where the message pane sits final JScrollPane scrollPane = new JScrollPane(textPane, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); panel.add(scrollPane);//from w w w . j a v a2 s . c o m panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(title), BorderFactory.createEmptyBorder(5, 5, 5, 5))); return panel; }
From source file:org.owasp.jbrofuzz.ui.viewers.WindowViewerFrame.java
/** * <p>// w ww . j a v a2s .c o m * The window viewer that gets launched for each request within the * corresponding panel. * </p> * * @param parent The parent panel that the frame will belong to * @param name The full file name of the file location to be opened * * @author subere@uncon.org * @version 2.0 * @since 2.0 */ public WindowViewerFrame(final AbstractPanel parent, final String name) { super("JBroFuzz - File Viewer - " + name); setIconImage(ImageCreator.IMG_FRAME.getImage()); // The container pane final Container pane = getContentPane(); pane.setLayout(new BorderLayout()); // Define the Panel final JPanel listPanel = new JPanel(); listPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(name), BorderFactory.createEmptyBorder(1, 1, 1, 1))); listPanel.setLayout(new BorderLayout()); // Get the preferences for wrapping lines of text final boolean wrapText = JBroFuzz.PREFS.getBoolean(JBroFuzzPrefs.FUZZING[3].getId(), false); if (wrapText) { listTextArea = new JTextPane(); } else { listTextArea = new NonWrappingTextPane(); } // Refine the Text Area listTextArea.setFont(new Font("Monospaced", Font.PLAIN, 12)); listTextArea.setEditable(false); // Define the search area entry = new JTextField(10); status = new JLabel("Enter text to search:"); // Initialise the highlighter on the text area hilit = new DefaultHighlighter(); painter = new DefaultHighlighter.DefaultHighlightPainter(HILIT_COLOR); listTextArea.setHighlighter(hilit); entryBg = entry.getBackground(); entry.getDocument().addDocumentListener(this); final InputMap im = entry.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); final ActionMap am = entry.getActionMap(); im.put(KeyStroke.getKeyStroke("ESCAPE"), CANCEL_ACTION); am.put(CANCEL_ACTION, new CancelAction()); // Right click: Cut, Copy, Paste, Select All AbstractPanel.popupText(listTextArea, false, true, false, true); // Define the Scroll Pane for the Text Area final JScrollPane listTextScrollPane = new JScrollPane(listTextArea); listTextScrollPane.setVerticalScrollBarPolicy(20); listTextScrollPane.setHorizontalScrollBarPolicy(30); // Define the progress bar final JProgressBar progressBar = new JProgressBar(); progressBar.setString(" "); progressBar.setStringPainted(true); // Define the bottom panel with the progress bar final JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 15, 15)); bottomPanel.add(status); bottomPanel.add(entry); bottomPanel.add(progressBar); listTextArea.setCaretPosition(0); // doSyntaxHighlight(); /* listTextArea.setEditorKit(new StyledEditorKit() { private static final long serialVersionUID = -6085642347022880064L; @Override public Document createDefaultDocument() { return new TextHighlighter(); } }); */ listPanel.add(listTextScrollPane); // Global Frame Issues pane.add(listPanel, BorderLayout.CENTER); pane.add(bottomPanel, BorderLayout.SOUTH); this.setLocation(parent.getLocationOnScreen().x + 100, parent.getLocationOnScreen().y + 20); this.setSize(SIZE_X, SIZE_Y); setResizable(true); setVisible(true); setMinimumSize(new Dimension(SIZE_X, SIZE_Y)); setDefaultCloseOperation(2); listTextArea.addKeyListener(new KeyAdapter() { @Override public void keyPressed(final KeyEvent ke) { if (ke.getKeyCode() == 27) { WindowViewerFrame.this.dispose(); } if (ke.getKeyCode() == 10) { search(); } } }); entry.addKeyListener(new KeyAdapter() { @Override public void keyPressed(final KeyEvent ke) { if (ke.getKeyCode() == 10) { search(); } } }); class FileLoader extends SwingWorker<String, Object> { // NO_UCD @Override public String doInBackground() { progressBar.setIndeterminate(true); String dbType = JBroFuzz.PREFS.get(JBroFuzzPrefs.DBSETTINGS[11].getId(), "-1"); if (dbType.equals("SQLite") || dbType.equals("CouchDB")) { String sessionId = parent.getFrame().getJBroFuzz().getWindow().getPanelFuzzing() .getSessionName(); if (sessionId == null || sessionId.equals("null")) { sessionId = JBroFuzz.PREFS.get("sessionId", ""); } Logger.log("Reading Session: " + sessionId + " with name: " + name, 3); MessageContainer mc = parent.getFrame().getJBroFuzz().getStorageHandler() .readFuzzFile(name, sessionId, parent.getFrame().getJBroFuzz().getWindow()).get(0); listTextArea.setText("Date: " + mc.getEndDateFull() + "\n" + "FileName: " + mc.getFileName() + "\n" + "URL: " + mc.getTextURL() + "\n" + "Payload: " + mc.getPayload() + "\n" + "EncodedPayload: " + mc.getEncodedPayload() + "\n" + "TextRequest:" + mc.getTextRequest() + "\n" + "Message: " + mc.getMessage() + "\n" + "Status: " + mc.getStatus() + "\n" ); } else { Logger.log("Loading data from file", 3); final File inputFile = new File(parent.getFrame().getJBroFuzz().getWindow().getPanelFuzzing() .getFrame().getJBroFuzz().getStorageHandler().getLocationURIString(), name + ".html"); listTextArea.setText( FileHandler.readFile(inputFile) ); } return "done"; } @Override protected void done() { progressBar.setIndeterminate(false); progressBar.setValue(100); listTextArea.repaint(); } } (new FileLoader()).execute(); }
From source file:org.pmedv.blackboard.board.BoardDesignerPerspective.java
@Override protected void initializeComponents() { setLayout(new BorderLayout()); toolTabPane = new JTabbedPane(JTabbedPane.BOTTOM); horizontalSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); ctx = AppContext.getContext();//from ww w. j a v a2 s.c o m resources = ctx.getBean(ResourceService.class); advisor = ctx.getBean(ApplicationWindowAdvisor.class); final String position = (String) Preferences.values .get("org.pmedv.blackboard.BoardDesignerPerspective.layerPanelPlacement"); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { viewMap = new ViewMap(); rootWindow = DockingUtil.createRootWindow(viewMap, true); rootWindow.getWindowBar(Direction.DOWN).setEnabled(true); rootWindow.getWindowProperties().setMinimizeEnabled(true); DockingWindowsTheme theme = new SoftBlueIceDockingTheme(); rootWindow.getRootWindowProperties().addSuperObject(theme.getRootWindowProperties()); rootWindow.getWindowProperties().getTabProperties().getHighlightedButtonProperties() .getCloseButtonProperties().setVisible(false); rootWindow.getWindowProperties().getTabProperties().getNormalButtonProperties() .getCloseButtonProperties().setVisible(false); editorArea = new TabWindow(); editorArea.getWindowProperties().getTabProperties().getNormalButtonProperties() .getCloseButtonProperties().setVisible(false); editorArea.getWindowProperties().getTabProperties().getHighlightedButtonProperties() .getCloseButtonProperties().setVisible(false); editorArea.getWindowProperties().getTabProperties().getNormalButtonProperties() .getMinimizeButtonProperties().setVisible(true); editorArea.getWindowProperties().getTabProperties().getHighlightedButtonProperties() .getMinimizeButtonProperties().setVisible(true); DockingWindowAdapter dockingAdapter = new DockingWindowAdapter() { @Override public void windowClosing(DockingWindow window) throws OperationAbortedException { } }; editorArea.addListener(dockingAdapter); setDockingListener(dockingAdapter); rootWindow.setWindow(editorArea); if (position.equalsIgnoreCase("left")) { horizontalSplitPane.setRightComponent(rootWindow); } else { horizontalSplitPane.setLeftComponent(rootWindow); } advisor.setCurrentEditorArea(editorArea); } }); JXTaskPaneContainer taskpanecontainer = new JXTaskPaneContainer(); taskpanecontainer.setBackground(new Color(182, 191, 205)); JXTaskPane shapePane = new JXTaskPane(); shapePane.setTitle(resources.getResourceByKey("BoardDesignerPerspective.shapes.title")); shapePane.add(ctx.getBean(ShapePropertiesPanel.class)); taskpanecontainer.add(shapePane); ctx.getBean(ShapePropertiesPanel.class).getStartLineCombo().setSelectedItem(LineEdgeType.STRAIGHT); ctx.getBean(ShapePropertiesPanel.class).getEndLineCombo().setSelectedItem(LineEdgeType.STRAIGHT); ctx.getBean(ShapePropertiesPanel.class).getThicknessCombo().setSelectedItem(new BasicStroke(2.0f)); JXTaskPane layerPane = new JXTaskPane(); layerPane.setTitle(resources.getResourceByKey("BoardDesignerPerspective.layers")); layerPane.add(ctx.getBean(ShowLayersCommand.class).getLayerPanel()); taskpanecontainer.add(layerPane); JScrollPane scrollPane = new JScrollPane(taskpanecontainer); if (position.equalsIgnoreCase("left")) { horizontalSplitPane.setLeftComponent(toolTabPane); } else { horizontalSplitPane.setRightComponent(toolTabPane); } horizontalSplitPane.setOneTouchExpandable(true); horizontalSplitPane.setDividerSize(10); toolTabPane.addTab(resources.getResourceByKey("tooltab.forms"), resources.getIcon("icon.paint"), scrollPane); final SymbolListPanel symbolListPanel = ctx.getBean(SymbolListPanel.class); toolTabPane.addTab(resources.getResourceByKey("tooltab.symbols"), resources.getIcon("icon.symbols"), symbolListPanel); final ModelListPanel modelListPanel = ctx.getBean(ModelListPanel.class); toolTabPane.addTab(resources.getResourceByKey("tooltab.models"), resources.getIcon("icon.model"), modelListPanel); add(horizontalSplitPane, BorderLayout.CENTER); commandArea = new RSyntaxTextArea(); commandArea.setRows(1); commandArea.setColumns(100); JPanel commandPanel = new JPanel(new BorderLayout()); commandPanel.add(new JLabel("Command :"), BorderLayout.WEST); commandPanel.add(commandArea, BorderLayout.CENTER); commandArea.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2), BorderFactory.createLineBorder(Color.BLACK))); add(commandPanel, BorderLayout.NORTH); setupAutoComplete(); commandArea.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { if (commandArea.getText().startsWith("add ") && commandArea.getText().length() > 4 && commandArea.hasFocus()) { PartFactory pf = AppContext.getContext().getBean(PartFactory.class); String tokens[] = commandArea.getText().split(" "); StringBuffer partName = new StringBuffer(); for (int i = 1; i < tokens.length; i++) { partName.append(tokens[i] + " "); } String name = partName.toString().trim(); if (pf.getPartnames().contains(name)) { e.consume(); commandArea.setText(""); BoardUtil.addPart(name, EditorUtils.getCurrentActiveEditor()); } } else if (commandArea.getText().equals("new")) { e.consume(); commandArea.setText(""); AppContext.getContext().getBean(CreateBoardCommand.class).execute(null); } else if (commandArea.getText().equals("resistor")) { e.consume(); commandArea.setText(""); AppContext.getContext().getBean(AddResistorCommand.class).execute(null); } else if (commandArea.getText().equals("diode")) { e.consume(); commandArea.setText(""); AppContext.getContext().getBean(AddDiodeCommand.class).execute(null); } else if (commandArea.getText().equals("text")) { e.consume(); commandArea.setText(""); AppContext.getContext().getBean(AddTextCommand.class).execute(null); } else if (commandArea.getText().equals("open")) { e.consume(); commandArea.setText(""); new OpenBoardCommand().execute(null); } else if (commandArea.getText().equals("save")) { e.consume(); commandArea.setText(""); AppContext.getContext().getBean(SaveBoardCommand.class).execute(null); } else if (commandArea.getText().equals("color")) { e.consume(); commandArea.setText(""); AppContext.getContext().getBean(ChooseColorCommand.class).execute(null); } } } }); horizontalSplitPane.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equalsIgnoreCase("dividerLocation")) { configProvider.getConfig().setDividerLocation(horizontalSplitPane.getDividerLocation()); } } }); ctx.getBean(ShapePropertiesPanel.class).getObjectField() .setText(resources.getResourceByKey("ShapePropertiesPanel.items.none")); ctx.getBean(ShapePropertiesPanel.class).getRotationSpinner().setEnabled(false); ctx.getBean(ShapePropertiesPanel.class).getStartAngleSpinner().setEnabled(false); initListeners(); }
From source file:org.pmedv.blackboard.commands.OpenBoardCommand.java
@Override public void execute(ActionEvent e) { final ApplicationWindow win = ctx.getBean(ApplicationWindow.class); // No file selected before, popup a dialog and query the user which file to open. if (file == null) { String path = System.getProperty("user.home"); if (AppContext.getLastSelectedFolder() != null) { path = AppContext.getLastSelectedFolder(); }/*from w w w . jav a 2 s. c o m*/ JFileChooser fc = new JFileChooser(path); fc.setDialogTitle(resources.getResourceByKey("OpenBoardCommand.name")); fc.setFileFilter(new FefaultFileFilter()); int result = fc.showOpenDialog(win); if (result == JFileChooser.APPROVE_OPTION) { if (fc.getSelectedFile() == null) return; file = fc.getSelectedFile(); AppContext.setLastSelectedFolder(file.getParentFile().getAbsolutePath()); } else { return; } } final JWindow topWindow = new JWindow(); topWindow.setSize(390, 50); topWindow.setLayout(new BorderLayout()); topWindow.setBackground(Color.WHITE); final JPanel content = new JPanel(new BorderLayout()); content.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.BLACK), BorderFactory.createEmptyBorder(10, 10, 10, 10))); content.setBackground(Color.WHITE); final JLabel infoLabel = new JLabel( resources.getResourceByKey("OpenBoardCommand.waitMsg") + " " + file.getName()); infoLabel.setVerticalAlignment(SwingConstants.CENTER); content.add(infoLabel, BorderLayout.SOUTH); final JBusyComponent<JPanel> busyPanel = new JBusyComponent<JPanel>(content); busyPanel.setBusy(true); topWindow.getContentPane().add(busyPanel, BorderLayout.CENTER); topWindow.setLocationRelativeTo(null); topWindow.add(busyPanel, BorderLayout.CENTER); final SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() { @Override protected Boolean doInBackground() { topWindow.setVisible(true); doOpen(); return Boolean.valueOf(true); } @Override protected void done() { topWindow.setVisible(false); topWindow.dispose(); for (Runnable r : postConfigurators) { SwingUtilities.invokeLater(r); } } }; worker.execute(); }
From source file:org.pmedv.blackboard.components.BoardEditor.java
/** * Setup the context menu/*from w w w . j a v a 2 s.c o m*/ * * TODO : Should be externalized into an XML based configuration file. */ private void hookContextMenu() { popupMenu = new JPopupMenu(); popupMenu.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.GRAY, 1), BorderFactory.createEmptyBorder(5, 5, 5, 5))); popupMenu.add(ctx.getBean(SetSelectModeCommand.class)); popupMenu.add(ctx.getBean(SetDrawModeCommand.class)); // popupMenu.add(ctx.getBean(SetMoveModeCommand.class)); popupMenu.add(ctx.getBean(SetColorCommand.class)); popupMenu.addSeparator(); popupMenu.add(ctx.getBean(ToggleSnapToGridCommand.class)); popupMenu.add(ctx.getBean(ToggleGridCommand.class)); popupMenu.add(ctx.getBean(ToggleMirrorCommand.class)); popupMenu.addSeparator(); popupMenu.add(ctx.getBean(BrowsePartsCommand.class)); popupMenu.add(ctx.getBean(AddResistorCommand.class)); popupMenu.add(ctx.getBean(ExportImageCommand.class)); popupMenu.add(ctx.getBean(AddTextCommand.class)); popupMenu.addSeparator(); popupMenu.add(ctx.getBean(CopyCommand.class)); popupMenu.add(ctx.getBean(PasteCommand.class)); popupMenu.addSeparator(); popupMenu.add(ctx.getBean(UndoCommand.class)); popupMenu.add(ctx.getBean(RedoCommand.class)); popupMenu.addSeparator(); popupMenu.add(deleteCommand); popupMenu.addSeparator(); popupMenu.add(ctx.getBean(RotateCWCommand.class)); popupMenu.add(ctx.getBean(RotateCCWCommand.class)); popupMenu.add(ctx.getBean(FlipHorizontalCommand.class)); popupMenu.add(ctx.getBean(FlipVerticalCommand.class)); popupMenu.addSeparator(); popupMenu.add(ctx.getBean(MoveToLayerCommand.class)); popupMenu.add(ctx.getBean(ConvertToPartCommand.class)); popupMenu.add(ctx.getBean(ConvertToSymbolCommand.class)); popupMenu.add(ctx.getBean(BreakSymbolCommand.class)); popupMenu.add(ctx.getBean(AddSymbolToLibraryCommand.class)); popupMenu.addSeparator(); // popupMenu.add(ctx.getBean(EditPartCommand.class)); popupMenu.add(ctx.getBean(EditPropertiesCommand.class)); popupMenu.addSeparator(); final SimulateCircuitCommand simulateCommand = ctx.getBean(SimulateCircuitCommand.class); final JMenu simulatorMenu = new JMenu(resources.getResourceByKey("SimulateCircuitCommand.name")); simulatorMenu.setIcon(resources.getIcon("icon.simulate")); final SimulatorProvider provider = AppContext.getContext().getBean(SimulatorProvider.class); for (final SpiceSimulator simulator : provider.getElements()) { final JMenuItem item = new JMenuItem(simulator.getName()); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { simulateCommand.setSimulator(simulator); simulateCommand.execute(null); } }); simulatorMenu.add(item); } popupMenu.add(simulatorMenu); }
From source file:org.rdv.ui.ExportDialog.java
private void initComponents(List<String> channels, List<String> fileFormats) { channelModel = new DefaultListModel(); for (int i = 0; i < channels.size(); i++) { String channelName = (String) channels.get(i); Channel channel = RBNBController.getInstance().getChannel(channelName); String mime = channel.getMetadata("mime"); if (mime.equals("application/octet-stream")) { channelModel.addElement(new ExportChannel(channelName)); }/*from w w w . j av a 2 s .c o m*/ } JPanel container = new JPanel(); setContentPane(container); InputMap inputMap = container.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = container.getActionMap(); container.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weighty = 0; c.gridwidth = 1; c.gridheight = 1; c.ipadx = 0; c.ipady = 0; JLabel headerLabel = new JLabel("Select the time range and data channels to export."); headerLabel.setBackground(Color.white); headerLabel.setOpaque(true); headerLabel.setBorder( BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray), BorderFactory.createEmptyBorder(10, 10, 10, 10))); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 0; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(0, 0, 0, 0); container.add(headerLabel, c); JPanel timeButtonPanel = new JPanel(); timeButtonPanel.setLayout(new BorderLayout()); MouseListener hoverMouseListener = new MouseAdapter() { public void mouseEntered(MouseEvent e) { e.getComponent().setForeground(Color.red); } public void mouseExited(MouseEvent e) { e.getComponent().setForeground(Color.blue); } }; startTimeButton = new JButton(); startTimeButton.setBorder(null); startTimeButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); startTimeButton.setForeground(Color.blue); startTimeButton.addMouseListener(hoverMouseListener); startTimeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { double startTime = DateTimeDialog.showDialog(ExportDialog.this, timeSlider.getStart(), timeSlider.getMinimum(), timeSlider.getEnd()); if (startTime >= 0) { timeSlider.setStart(startTime); } } }); timeButtonPanel.add(startTimeButton, BorderLayout.WEST); durationLabel = new JLabel(); durationLabel.setHorizontalAlignment(JLabel.CENTER); timeButtonPanel.add(durationLabel, BorderLayout.CENTER); endTimeButton = new JButton(); endTimeButton.setBorder(null); endTimeButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); endTimeButton.setForeground(Color.blue); endTimeButton.addMouseListener(hoverMouseListener); endTimeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { double endTime = DateTimeDialog.showDialog(ExportDialog.this, timeSlider.getEnd(), timeSlider.getStart(), timeSlider.getMaximum()); if (endTime >= 0) { timeSlider.setEnd(endTime); } } }); timeButtonPanel.add(endTimeButton, BorderLayout.EAST); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 1; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(10, 10, 10, 10); container.add(timeButtonPanel, c); timeSlider = new TimeSlider(); timeSlider.setValueChangeable(false); timeSlider.setValueVisible(false); timeSlider.addTimeAdjustmentListener(new TimeAdjustmentListener() { public void timeChanged(TimeEvent event) { } public void rangeChanged(TimeEvent event) { updateTimeRangeLabel(); } public void boundsChanged(TimeEvent event) { } }); updateTimeRangeLabel(); updateTimeBounds(); List<EventMarker> markers = RBNBController.getInstance().getMarkerManager().getMarkers(); for (EventMarker marker : markers) { timeSlider.addMarker(marker); } c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 2; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(0, 10, 10, 10); container.add(timeSlider, c); JLabel numericHeaderLabel = new JLabel("Data Channels:"); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 3; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(0, 10, 10, 10); container.add(numericHeaderLabel, c); numericChannelList = new JList(channelModel); numericChannelList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); numericChannelList.setCellRenderer(new CheckListRenderer()); numericChannelList.setVisibleRowCount(10); numericChannelList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { int index = numericChannelList.locationToIndex(e.getPoint()); ExportChannel item = (ExportChannel) numericChannelList.getModel().getElementAt(index); item.setSelected(!item.isSelected()); Rectangle rect = numericChannelList.getCellBounds(index, index); numericChannelList.repaint(rect); checkSelectedChannels(); updateTimeBounds(); } }); JScrollPane scrollPane = new JScrollPane(numericChannelList); c.fill = GridBagConstraints.BOTH; c.weightx = 0; c.weighty = 1; c.gridx = 0; c.gridy = 4; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(0, 10, 10, 10); container.add(scrollPane, c); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.weighty = 0; c.gridx = 0; c.gridy = 5; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(0, 10, 10, 5); container.add(new JLabel("Data file: "), c); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridx = 1; c.gridy = 5; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; dataFileTextField = new JTextField(20); c.insets = new java.awt.Insets(0, 0, 10, 5); container.add(dataFileTextField, c); dataFileTextField .setText(UIUtilities.getCurrentDirectory().getAbsolutePath() + File.separator + "data.dat"); dataFileButton = new JButton("Browse"); dataFileButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { File selectedFile = new File(dataFileTextField.getText()); selectedFile = UIUtilities.getFile("OK", "Select export file", selectedFile); if (selectedFile != null) { dataFileTextField.setText(selectedFile.getAbsolutePath()); } } }); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 2; c.gridy = 5; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(0, 0, 10, 10); container.add(dataFileButton, c); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 0; c.gridy = 6; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(0, 10, 10, 5); container.add(new JLabel("File format: "), c); fileFormatComboBox = new JComboBox(fileFormats.toArray()); fileFormatComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { fileFormatUpdated(); } }); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridx = 1; c.gridy = 6; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(0, 0, 10, 10); container.add(fileFormatComboBox, c); JPanel panel = new JPanel(); panel.setLayout(new FlowLayout()); Action exportAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = -5356258138620428023L; public void actionPerformed(ActionEvent e) { ok(); } }; exportAction.putValue(Action.NAME, "Export"); inputMap.put(KeyStroke.getKeyStroke("ENTER"), "export"); actionMap.put("export", exportAction); exportButton = new JButton(exportAction); panel.add(exportButton); Action cancelAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = -5868609501314154642L; public void actionPerformed(ActionEvent e) { cancel(); } }; cancelAction.putValue(Action.NAME, "Cancel"); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "cancel"); actionMap.put("cancel", cancelAction); cancelButton = new JButton(cancelAction); panel.add(cancelButton); c.fill = GridBagConstraints.NONE; c.weightx = 0.5; c.gridx = 0; c.gridy = 7; c.gridwidth = GridBagConstraints.REMAINDER; ; c.anchor = GridBagConstraints.LINE_END; c.insets = new java.awt.Insets(0, 0, 10, 5); container.add(panel, c); pack(); if (getWidth() < 600) { setSize(600, getHeight()); } dataFileTextField.requestFocusInWindow(); setLocationByPlatform(true); }
From source file:org.rdv.ui.ExportVideoDialog.java
private void initComponents() { JPanel container = new JPanel(); setContentPane(container);//from w w w .j ava2s . co m InputMap inputMap = container.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = container.getActionMap(); container.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weighty = 0; c.gridwidth = 1; c.gridheight = 1; c.ipadx = 0; c.ipady = 0; JLabel headerLabel = new JLabel("Select the time range and video channels to export."); headerLabel.setBackground(Color.white); headerLabel.setOpaque(true); headerLabel.setBorder( BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray), BorderFactory.createEmptyBorder(10, 10, 10, 10))); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 0; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(0, 0, 0, 0); container.add(headerLabel, c); JPanel timeButtonPanel = new JPanel(); timeButtonPanel.setLayout(new BorderLayout()); MouseListener hoverMouseListener = new MouseAdapter() { public void mouseEntered(MouseEvent e) { e.getComponent().setForeground(Color.red); } public void mouseExited(MouseEvent e) { e.getComponent().setForeground(Color.blue); } }; startTimeButton = new JButton(); startTimeButton.setBorder(null); startTimeButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); startTimeButton.setForeground(Color.blue); startTimeButton.addMouseListener(hoverMouseListener); startTimeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { double startTime = DateTimeDialog.showDialog(ExportVideoDialog.this, timeSlider.getStart(), timeSlider.getMinimum(), timeSlider.getEnd()); if (startTime >= 0) { timeSlider.setStart(startTime); } } }); timeButtonPanel.add(startTimeButton, BorderLayout.WEST); durationLabel = new JLabel(); durationLabel.setHorizontalAlignment(JLabel.CENTER); timeButtonPanel.add(durationLabel, BorderLayout.CENTER); endTimeButton = new JButton(); endTimeButton.setBorder(null); endTimeButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); endTimeButton.setForeground(Color.blue); endTimeButton.addMouseListener(hoverMouseListener); endTimeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { double endTime = DateTimeDialog.showDialog(ExportVideoDialog.this, timeSlider.getEnd(), timeSlider.getStart(), timeSlider.getMaximum()); if (endTime >= 0) { timeSlider.setEnd(endTime); } } }); timeButtonPanel.add(endTimeButton, BorderLayout.EAST); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 1; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(10, 10, 10, 10); container.add(timeButtonPanel, c); timeSlider = new TimeSlider(); timeSlider.setValueChangeable(false); timeSlider.setValueVisible(false); timeSlider.addTimeAdjustmentListener(new TimeAdjustmentListener() { public void timeChanged(TimeEvent event) { } public void rangeChanged(TimeEvent event) { updateTimeRangeLabel(); } public void boundsChanged(TimeEvent event) { } }); updateTimeRangeLabel(); updateTimeBounds(); List<EventMarker> markers = rbnb.getMarkerManager().getMarkers(); for (EventMarker marker : markers) { timeSlider.addMarker(marker); } c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 2; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(0, 10, 10, 10); container.add(timeSlider, c); JLabel numericHeaderLabel = new JLabel("Video Channels:"); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 3; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(0, 10, 10, 10); container.add(numericHeaderLabel, c); videoChannelList = new JList(videoChannelModel); videoChannelList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); videoChannelList.setCellRenderer(new CheckListRenderer()); videoChannelList.setVisibleRowCount(10); videoChannelList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { int index = videoChannelList.locationToIndex(e.getPoint()); ExportChannel item = (ExportChannel) videoChannelList.getModel().getElementAt(index); item.setSelected(!item.isSelected()); Rectangle rect = videoChannelList.getCellBounds(index, index); videoChannelList.repaint(rect); updateTimeBounds(); } }); JScrollPane scrollPane = new JScrollPane(videoChannelList); c.fill = GridBagConstraints.BOTH; c.weightx = 0; c.weighty = 1; c.gridx = 0; c.gridy = 4; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(0, 10, 10, 10); container.add(scrollPane, c); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.weighty = 0; c.gridx = 0; c.gridy = 5; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(0, 10, 10, 5); container.add(new JLabel("Choose Directory: "), c); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridx = 1; c.gridy = 5; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; directoryTextField = new JTextField(20); c.insets = new java.awt.Insets(0, 0, 10, 5); container.add(directoryTextField, c); directoryTextField.setText(UIUtilities.getCurrentDirectory().getAbsolutePath()); directoryButton = new JButton("Browse"); directoryButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { File selectedDirectory = UIUtilities.getDirectory("Select export directory"); if (selectedDirectory != null) { directoryTextField.setText(selectedDirectory.getAbsolutePath()); } } }); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 2; c.gridy = 5; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(0, 0, 10, 10); container.add(directoryButton, c); exportProgressBar = new JProgressBar(0, 100000); exportProgressBar.setStringPainted(true); exportProgressBar.setValue(0); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0.5; c.gridx = 0; c.gridy = 6; c.gridwidth = GridBagConstraints.REMAINDER; ; c.anchor = GridBagConstraints.CENTER; c.insets = new java.awt.Insets(0, 10, 10, 10); container.add(exportProgressBar, c); JPanel panel = new JPanel(); panel.setLayout(new FlowLayout()); Action exportAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = 1547500154252213911L; public void actionPerformed(ActionEvent e) { exportVideo(); } }; exportAction.putValue(Action.NAME, "Export"); inputMap.put(KeyStroke.getKeyStroke("ENTER"), "export"); actionMap.put("export", exportAction); exportButton = new JButton(exportAction); panel.add(exportButton); Action cancelAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = -7440298547807878651L; public void actionPerformed(ActionEvent e) { cancel(); } }; cancelAction.putValue(Action.NAME, "Cancel"); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "cancel"); actionMap.put("cancel", cancelAction); cancelButton = new JButton(cancelAction); panel.add(cancelButton); c.fill = GridBagConstraints.NONE; c.weightx = 0.5; c.gridx = 0; c.gridy = 7; c.gridwidth = GridBagConstraints.REMAINDER; ; c.anchor = GridBagConstraints.LINE_END; c.insets = new java.awt.Insets(0, 0, 10, 5); container.add(panel, c); pack(); if (getWidth() < 600) { setSize(600, getHeight()); } directoryTextField.requestFocusInWindow(); setLocationByPlatform(true); setVisible(true); }
From source file:org.rdv.ui.ImportDialog.java
private void initComponents() { JPanel container = new JPanel(); setContentPane(container);// w w w. ja v a 2 s . co m InputMap inputMap = container.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = container.getActionMap(); container.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; c.gridwidth = 1; c.gridheight = 1; c.ipadx = 0; c.ipady = 0; JLabel headerLabel = new JLabel("Please specify the desired source name for the data."); headerLabel.setBackground(Color.white); headerLabel.setOpaque(true); headerLabel.setBorder( BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray), BorderFactory.createEmptyBorder(10, 10, 10, 10))); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 0; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(0, 0, 0, 0); container.add(headerLabel, c); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new java.awt.Insets(10, 10, 10, 5); container.add(new JLabel("Source name: "), c); sourceNameTextField = new JTextField(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridx = 1; c.gridy = 1; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new java.awt.Insets(10, 0, 10, 10); container.add(sourceNameTextField, c); importProgressBar = new JProgressBar(0, 100000); importProgressBar.setStringPainted(true); importProgressBar.setValue(0); importProgressBar.setVisible(false); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0.5; c.gridx = 0; c.gridy = 2; c.gridwidth = GridBagConstraints.REMAINDER; ; c.anchor = GridBagConstraints.CENTER; c.insets = new java.awt.Insets(0, 10, 10, 10); container.add(importProgressBar, c); JPanel panel = new JPanel(); panel.setLayout(new FlowLayout()); Action importAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = -4719316285523193555L; public void actionPerformed(ActionEvent e) { importData(); } }; importAction.putValue(Action.NAME, "Import"); inputMap.put(KeyStroke.getKeyStroke("ENTER"), "import"); actionMap.put("export", importAction); importButton = new JButton(importAction); getRootPane().setDefaultButton(importButton); panel.add(importButton); Action cancelAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = 7909429022904810958L; public void actionPerformed(ActionEvent e) { cancel(); } }; cancelAction.putValue(Action.NAME, "Cancel"); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "cancel"); actionMap.put("cancel", cancelAction); cancelButton = new JButton(cancelAction); panel.add(cancelButton); c.fill = GridBagConstraints.NONE; c.weightx = 0.5; c.gridx = 0; c.gridy = 3; c.gridwidth = GridBagConstraints.REMAINDER; ; c.anchor = GridBagConstraints.LINE_END; c.insets = new java.awt.Insets(0, 0, 10, 5); container.add(panel, c); pack(); sourceNameTextField.requestFocusInWindow(); setLocationByPlatform(true); setVisible(true); }
From source file:org.rdv.ui.LoginDialog.java
public LoginDialog(JFrame owner) { super(owner, true); setDefaultCloseOperation(DISPOSE_ON_CLOSE); setTitle("Login to NEES"); JPanel container = new JPanel(); setContentPane(container);//from w w w.ja v a2 s . c o m InputMap inputMap = container.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = container.getActionMap(); container.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; c.gridwidth = 1; c.gridheight = 1; c.ipadx = 0; c.ipady = 0; headerLabel = new JLabel("Please specify your NEES account information."); headerLabel.setBackground(Color.white); headerLabel.setOpaque(true); headerLabel.setBorder( BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray), BorderFactory.createEmptyBorder(10, 10, 10, 10))); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new Insets(0, 0, 0, 0); container.add(headerLabel, c); errorLabel = new JLabel(); errorLabel.setVisible(false); errorLabel.setForeground(Color.RED); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 1; c.insets = new Insets(10, 10, 0, 10); container.add(errorLabel, c); c.gridwidth = 1; userNameLabel = new JLabel("Username:"); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 0; c.gridy = 2; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new Insets(10, 10, 10, 5); container.add(userNameLabel, c); userNameTextField = new JTextField("", 25); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridx = 1; c.gridy = 2; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new Insets(10, 0, 10, 10); container.add(userNameTextField, c); userPasswordLabel = new JLabel("Password:"); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 0; c.gridy = 3; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new Insets(0, 10, 10, 5); container.add(userPasswordLabel, c); userPasswordField = new JPasswordField(16); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridx = 1; c.gridy = 3; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new Insets(0, 0, 10, 10); container.add(userPasswordField, c); JPanel buttonPanel = new JPanel(); Action loginAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = -5591044023056646223L; public void actionPerformed(ActionEvent e) { login(); } }; loginAction.putValue(Action.NAME, "Login"); inputMap.put(KeyStroke.getKeyStroke("ENTER"), "login"); actionMap.put("login", loginAction); loginButton = new JButton(loginAction); buttonPanel.add(loginButton); Action cancelAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = 6237115705468556255L; public void actionPerformed(ActionEvent e) { cancel(); } }; cancelAction.putValue(Action.NAME, "Cancel"); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "cancel"); actionMap.put("cancel", cancelAction); cancelButton = new JButton(cancelAction); buttonPanel.add(cancelButton); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 0; c.gridy = 4; c.gridwidth = 2; c.anchor = GridBagConstraints.LINE_END; c.insets = new Insets(0, 10, 10, 5); container.add(buttonPanel, c); pack(); setLocationByPlatform(true); setVisible(true); }
From source file:org.rdv.ui.RBNBConnectionDialog.java
public RBNBConnectionDialog(JFrame owner, RBNBController rbnbController, DataPanelManager dataPanelManager) { super(owner, true); this.rbnb = rbnbController; this.dataPanelManager = dataPanelManager; setDefaultCloseOperation(DISPOSE_ON_CLOSE); setTitle("Connect to RBNB Server"); JPanel container = new JPanel(); setContentPane(container);// w w w .j av a 2 s . com InputMap inputMap = container.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = container.getActionMap(); container.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; c.gridwidth = 1; c.gridheight = 1; c.ipadx = 0; c.ipady = 0; headerLabel = new JLabel("Please specify the RBNB server connection information."); headerLabel.setBackground(Color.white); headerLabel.setOpaque(true); headerLabel.setBorder( BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray), BorderFactory.createEmptyBorder(10, 10, 10, 10))); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new Insets(0, 0, 0, 0); container.add(headerLabel, c); c.gridwidth = 1; rbnbHostNameLabel = new JLabel("Host:"); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 0; c.gridy = 1; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new Insets(10, 10, 10, 5); container.add(rbnbHostNameLabel, c); rbnbHostNameTextField = new JTextField(25); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridx = 1; c.gridy = 1; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new Insets(10, 0, 10, 10); container.add(rbnbHostNameTextField, c); rbnbPortLabel = new JLabel("Port:"); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 0; c.gridy = 2; c.anchor = GridBagConstraints.NORTHEAST; c.insets = new Insets(0, 10, 10, 5); container.add(rbnbPortLabel, c); rbnbPortTextField = new JTextField(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridx = 1; c.gridy = 2; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new Insets(0, 0, 10, 10); rbnbPortTextField.addFocusListener(new FocusListener() { public void focusGained(FocusEvent focusEvent) { rbnbPortTextField.setSelectionStart(0); rbnbPortTextField.setSelectionEnd(rbnbPortTextField.getText().length()); } public void focusLost(FocusEvent focusEvent) { } }); container.add(rbnbPortTextField, c); JPanel buttonPanel = new JPanel(); Action connectAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = 5814028508027064335L; public void actionPerformed(ActionEvent e) { connect(); } }; connectAction.putValue(Action.NAME, "Connect"); inputMap.put(KeyStroke.getKeyStroke("ENTER"), "connect"); actionMap.put("connect", connectAction); connectButton = new JButton(connectAction); buttonPanel.add(connectButton); Action cancelAction = new AbstractAction() { /** serialization version identifier */ private static final long serialVersionUID = -679192362775669088L; public void actionPerformed(ActionEvent e) { cancel(); } }; cancelAction.putValue(Action.NAME, "Cancel"); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "cancel"); actionMap.put("cancel", cancelAction); cancelButton = new JButton(cancelAction); buttonPanel.add(cancelButton); c.fill = GridBagConstraints.NONE; c.weightx = 0; c.gridx = 0; c.gridy = 3; c.gridwidth = 2; c.anchor = GridBagConstraints.LINE_END; c.insets = new Insets(0, 10, 10, 5); container.add(buttonPanel, c); pack(); setLocationByPlatform(true); setVisible(true); }