List of usage examples for javax.swing JButton addMouseListener
public synchronized void addMouseListener(MouseListener l)
From source file:org.ut.biolab.medsavant.client.project.ProjectWizard.java
private AbstractWizardPage getReferencePage() throws SQLException, RemoteException { //setup page/*from ww w .j av a 2s.c o m*/ final DefaultWizardPage page = new DefaultWizardPage(PAGENAME_REF) { @Override public void setupWizardButtons() { fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.BACK); fireButtonEvent(ButtonEvent.HIDE_BUTTON, ButtonNames.FINISH); fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT); } }; page.addText("Choose reference genome(s) to add to this project, along\n" + "with corresponding annotations. Annotations will be\n" + "applied to all variants added to these tables."); //setup list JScrollPane scrollpane = new JScrollPane(); scrollpane.setPreferredSize(new Dimension(300, 220)); scrollpane.getViewport().setBackground(Color.white); final JPanel p = new JPanel(); p.setBackground(Color.white); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); refreshReferencePanel(p); scrollpane.getViewport().add(p); page.addComponent(scrollpane); JButton addRefButton = new JButton("New Reference"); addRefButton.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { try { new NewReferenceDialog().setVisible(true); refreshReferencePanel(p); } catch (Exception ex) { ClientMiscUtils.reportError("Unable to retrieve references and annotations: %s", ex); } } }); page.addComponent(addRefButton); return page; }
From source file:org.ut.biolab.medsavant.client.view.component.ListViewTablePanel.java
public ListViewTablePanel(Object[][] data, String[] columnNames, Class[] columnClasses, int[] hiddenColumns, boolean allowSearch, boolean allowSort, boolean allowPages, boolean allowSelection) { this.hiddenColumns = hiddenColumns; table = new SortableTable() { @Override//w w w . jav a 2 s.c o m public Component prepareRenderer(TableCellRenderer renderer, int Index_row, int Index_col) { Component comp = super.prepareRenderer(renderer, Index_row, Index_col); //even index, selected or not selected if (isRowSelected(Index_row)) { comp.setBackground(ViewUtil.detailSelectedBackground); } else { if (Index_row % 2 == 0) { comp.setBackground(evenRowColor); } else { comp.setBackground(oddRowColor); } } comp.setForeground(ViewUtil.detailForeground); comp.setFont(comp.getFont().deriveFont(fontSize)); return comp; } }; table.setBorder(null); table.setSelectionForeground(Color.darkGray); table.setRowHeight(30); table.setClearSelectionOnTableDataChanges(true); table.setOptimized(true); table.setColumnAutoResizable(true); table.setAutoResort(false); //table.setDragEnabled(false); //table.setRowHeight(20); table.setSortable(allowSort); table.setSortingEnabled(allowSort); table.setFocusable(allowSelection); table.setCellSelectionEnabled(allowSelection); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setAutoResizeMode(SortableTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); //table.setMinimumSize(new Dimension(500,999)); //table.setPreferredSize(new Dimension(500,999)); //column chooser TableHeaderPopupMenuInstaller installer = new TableHeaderPopupMenuInstaller(table); installer.addTableHeaderPopupMenuCustomizer(new AutoResizePopupMenuCustomizer()); columnChooser = new ColumnChooser(table); installer.addTableHeaderPopupMenuCustomizer(columnChooser); AutoFilterTableHeader header = new AutoFilterTableHeader(table); header.setAutoFilterEnabled(true); header.setShowFilterIcon(true); header.setShowFilterName(true); table.setTableHeader(header); filterField = new QuickTableFilterField(model); filterField.setHintText("Type to search"); setLayout(new BorderLayout(3, 3)); fieldPanel = ViewUtil.getClearPanel(); fieldPanel.setLayout(new GridBagLayout()); setOpaque(false); GridBagConstraints gbc = new GridBagConstraints(); gbc.weightx = 1.0; //gbc.fill = GridBagConstraints.HORIZONTAL; gbc.fill = GridBagConstraints.BOTH; if (allowSearch) { fieldPanel.add(filterField, gbc); } if (columnNames.length > 1) { JButton chooseColumnButton = new JButton("Fields"); chooseColumnButton.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { columnChooser.showDialog(); } }); gbc.weightx = 0.0; gbc.fill = GridBagConstraints.NONE; fieldPanel.add(chooseColumnButton, gbc); } setTableModel(data, columnNames, columnClasses); if (allowSort) { add(fieldPanel, BorderLayout.NORTH); } JScrollPane jsp = new JScrollPane(table); jsp.setBorder(null); add(jsp, BorderLayout.CENTER); updateData(data); updateView(); }
From source file:pl.otros.logview.gui.LogViewPanel.java
protected void initMessageDetailsToolbar() { final JButton buttonFormatters = new JButton("Message formatters", Icons.MESSAGE_FORMATTER); buttonFormatters.addMouseListener(new MouseAdapter() { @Override/* w w w. j ava 2 s .co m*/ public void mouseClicked(MouseEvent e) { showMessageFormatterOrColorizerPopupMenu(e, "Message formatters", selectedMessageFormattersContainer, messageFormattersContainer); } }); buttonFormatters.setToolTipText("Select used message formatters"); messageDetailToolbar.add(buttonFormatters); final JButton buttonColorizers = new JButton("Message colorizers", Icons.MESSAGE_COLORIZER); buttonColorizers.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { showMessageFormatterOrColorizerPopupMenu(e, "Message colorizers", selectedMessageColorizersContainer, messageColorizersContainer); } }); buttonColorizers.setToolTipText("Select used message colorizers"); messageDetailToolbar.add(buttonColorizers); messageDetailToolbar.add(new CopyStyledMessageDetailAction(otrosApplication, dateFormat, selectedMessageColorizersContainer, selectedMessageFormattersContainer)); messageDetailToolbar.add(new JLabel("Maximum message size for format")); final DefaultComboBoxModel defaultComboBoxModel = new DefaultComboBoxModel(new String[] {}); String[] values = new String[] { "10kB", "100kB", "200kB", "300kB", "400kB", "500kB", "600kB", "700kB", "800kB", "900kB", "1MB", "2MB", "3MB", "4MB", "5MB" }; for (String value : values) { defaultComboBoxModel.addElement(value); } final JXComboBox messageMaximumSize = new JXComboBox(defaultComboBoxModel); messageMaximumSize.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String max = (String) defaultComboBoxModel.getElementAt(messageMaximumSize.getSelectedIndex()); configuration.setProperty(ConfKeys.MESSAGE_FORMATTER_MAX_SIZE, max); messageDetailListener.setMaximumMessageSize((int) new FileSize(max).getBytes()); } }); messageMaximumSize.setEditable(false); AutoCompleteDecorator.decorate(messageMaximumSize); messageMaximumSize.setMaximumSize(new Dimension(100, 50)); messageDetailToolbar.add(messageMaximumSize); String messageMaxSize = configuration.getString(ConfKeys.MESSAGE_FORMATTER_MAX_SIZE, (String) defaultComboBoxModel.getElementAt(messageMaximumSize.getSelectedIndex())); if (defaultComboBoxModel.getIndexOf(messageMaxSize) >= 0) { messageMaximumSize.setSelectedItem(messageMaxSize); } }
From source file:savant.export.ExportPlugin.java
private void setupGUI(JPanel panel) { panel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); //create padding gbc.fill = GridBagConstraints.BOTH; gbc.weightx = 0;//from w w w . ja v a2 s . co m gbc.weighty = 0; gbc.gridx = 0; gbc.gridy = 0; JPanel fill1 = new JPanel(); fill1.setPreferredSize(new Dimension(10, 10)); panel.add(fill1, gbc); //create path chooser JLabel htmlLabel = new JLabel( "<html>Choose folder to save files.<br>An html index file will be created here.</html>"); gbc.gridwidth = 2; gbc.gridx = 1; gbc.gridy = 1; panel.add(htmlLabel, gbc); pf = new PathField(JFileChooser.OPEN_DIALOG, false, true); gbc.gridx = 1; gbc.gridy = 2; panel.add(pf, gbc); //create runExport button JButton runButton = new JButton("Run"); runButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { exportThread = new Thread("Export Plugin") { @Override public void run() { try { runTool(); } catch (InterruptedException ex) { //TODO: deal with exception? LOG.error("Export interrupted.", ex); } } }; exportThread.start(); //create progress dialog Object[] options = { "Cancel" }; progressPanel = new JOptionPane(" Running Export: 1"); progressPanel.setOptions(options); progressDialog = progressPanel.createDialog("Export in progress"); progressDialog.setVisible(true); if (progressPanel.getValue().equals("Cancel")) { exportCancelled = true; } } }); gbc.weightx = 0; gbc.gridwidth = 1; gbc.weightx = 0; gbc.weighty = 0; gbc.gridx = 1; gbc.gridy = 3; panel.add(runButton, gbc); //create output label outputLabel = new JLabel(); Font f = outputLabel.getFont(); outputLabel.setFont(f.deriveFont(f.getStyle() ^ Font.BOLD)); gbc.gridx = 2; gbc.gridy = 3; panel.add(outputLabel, gbc); //create padding JPanel fill2 = new JPanel(); fill2.setPreferredSize(new Dimension(10, 10)); gbc.weightx = 1.0; gbc.gridwidth = 1; gbc.gridx = 2; gbc.gridy = 3; panel.add(fill2, gbc); JPanel fill3 = new JPanel(); fill3.setPreferredSize(new Dimension(10, 10)); gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.gridwidth = 2; gbc.gridx = 0; gbc.gridy = 4; panel.add(fill3, gbc); }
From source file:studio.ui.Studio.java
private void rebuildMenus(TabIndexChanged event) { AppMenuBar appMenubar = getJMenuBar() instanceof AppMenuBar ? (AppMenuBar) getJMenuBar() : null; ToolBarActions toolBar = null;/*from w w w. j a v a 2 s .c o m*/ ActionMenu menuBar = null; if (appToolbar == null && appMenubar == null) { appToolbar = new ToolBarActions(); getContentPane().add(appToolbar, BorderLayout.NORTH); appMenubar = new AppMenuBar(); setJMenuBar(appMenubar); toolBar = new ToolBarActions("File"); menuBar = new ActionMenu("File", 'f', "File operations", (MouseAdapter) null); Action action = new NewFileAction(tabEditors, tabConsoles); JPopupMenu popupMenu = new JPopupMenu(); JMenuItem item = new JMenuItem("Script"); item.setToolTipText("New script"); item.addMouseListener(new ActionHintsListener(tabEditors, "Create new script")); item.addActionListener(action); popupMenu.add(item); item = new JMenuItem("Project"); item.setToolTipText("New project"); item.addMouseListener(new ActionHintsListener(tabEditors, "Create new project")); try { item.addActionListener(new AddProjectAction(treeProjects)); popupMenu.add(item); } catch (StudioException ex) { } JButton button = new DropDownButton(action, popupMenu); if (button instanceof DataListener) { tabEditors.addFireDataListener((DataListener) button); } button.addMouseListener(new ActionHintsListener(tabEditors, action)); toolBar.add(button); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); action = new OpenFileAction(tabEditors, tabConsoles); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); popupMenu = null; if (studioConfig.getOpenedFiles() != null && !studioConfig.getOpenedFiles().isEmpty()) { popupMenu = new JPopupMenu(); int pos = 0; for (EditorFile file : studioConfig.getOpenedFiles()) { item = new JMenuItem((char) (pos + 48) + " " + file.getPath(), pos + 48); item.addMouseListener(new ActionHintsListener(tabEditors, "Open file " + file)); popupMenu.add(item); if (++pos > 9) { break; } } } button = new DropDownButton(action, popupMenu); if (button instanceof DataListener) { tabEditors.addFireDataListener((DataListener) button); } button.addMouseListener(new ActionHintsListener(tabEditors, action)); toolBar.add(button); appToolbar.add(toolBar); appMenubar.add(menuBar); appToolbar.add(new ToolBarActions("KDB+")); appMenubar.add(new ActionMenu("KDB+", 'k', "KDB+ databse operations", (MouseAdapter) null)); appToolbar.add(new ToolBarActions("Edit")); appMenubar.add(new ActionMenu("Edit", 'E', "Editor operations", (MouseAdapter) null)); toolBar = new ToolBarActions("Options"); appToolbar.add(toolBar); menuBar = new ActionMenu("Tools", 'T', "Tools", (MouseAdapter) null); ActionMenu opMenuBar = new ActionMenu("Options", 'O', "Studio settings", (MouseAdapter) null); ActionMenu lfMenuBar = new ActionMenu("Look and feel", 'L', "L&F", (MouseAdapter) null); LookAndFeelAction.getActionLookAndFeel(this, lfMenuBar, studioConfig); opMenuBar.add(lfMenuBar); opMenuBar.addSeparator(); action = new EditorSettingsAction(this); opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); action = new TokensSettingsAction(this); opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); opMenuBar.addSeparator(); action = new ConsoleSettingsAction(this); opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); opMenuBar.addSeparator(); action = new ConnectionsSettingsAction(treeConnections); opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); menuBar.add(opMenuBar); opMenuBar.addSeparator(); action = new GlobalSettingsAction(this); opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); appMenubar.add(menuBar); opMenuBar.addSeparator(); action = new ProjectSettingsAction(this); opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); appMenubar.add(menuBar); menuBar = new ActionMenu("Help", 'H', "Help...", (MouseAdapter) null); action = new VisitKxAction(); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); menuBar.addSeparator(); action = new VisitWroclawAction(); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); menuBar.addSeparator(); action = new KeyListAction(tabEditors); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); menuBar.addSeparator(); action = new AboutAction(tabEditors); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); appMenubar.add(menuBar); menuBar.addSeparator(); action = new CheckUpdate(this); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); appMenubar.add(menuBar); toolBar = null; this.setJMenuBar(appMenubar); } appToolbar.getToolBar("Edit").setVisible(event != null && event.getData() != -1); appToolbar.getToolBar("Options").setVisible(event != null && event.getData() != -1); appToolbar.getToolBar("KDB+").setVisible(event != null && event.getData() != -1); appToolbar.getToolBar("File").setVisible(event != null && event.getData() != -1); appMenubar.getMenu("Edit").setVisible(event != null && event.getData() != -1); appMenubar.getMenu("Tools").setVisible(event != null && event.getData() != -1); appMenubar.getMenu("KDB+").setVisible(event != null && event.getData() != -1); appMenubar.getMenu("File").setVisible(event != null && event.getData() != -1); if (event != null && event.getSource() instanceof EditorsTabbedPane && event.getData() != -1) { Editor editor = ((EditorsTabbedPane) event.getSource()).getEditor(event.getData()); if (editor != null) { JPopupMenu menu = editor.getComponentPopupMenu(); if (menu != null) { for (int count = 0; count < menu.getComponentCount(); count++) { if (menu.getComponent(count) instanceof JMenuItem) { JMenuItem menuItem = (JMenuItem) menu.getComponent(count); if (menuItem.getAction().getClass() == SaveAction.class) { appToolbar.getToolBar("File").update(tabEditors, menuItem.getAction(), true); appMenubar.getMenu("File").update(tabEditors, menuItem.getAction(), true); } else { if (menuItem.getAction().getClass() == SaveAsAction.class || menuItem.getAction().getClass() == SaveAllAction.class) { appToolbar.getToolBar("File").update(tabEditors, menuItem.getAction()); appMenubar.getMenu("File").update(tabEditors, menuItem.getAction()); } else { if (menuItem.getAction().getClass() == CloseAction.class) { appToolbar.getToolBar("File").update(tabEditors, menuItem.getAction(), true); appMenubar.getMenu("File").update(tabEditors, menuItem.getAction(), true); } else { if (menuItem.getAction().getClass() == CloseAllAction.class) { appToolbar.getToolBar("File").update(tabEditors, menuItem.getAction()); appMenubar.getMenu("File").update(tabEditors, menuItem.getAction()); } else { if (menuItem.getAction().getClass() == RunAction.class || menuItem.getAction().getClass() == RunLineAction.class || menuItem.getAction().getClass() == CancelRunAction.class) { appToolbar.getToolBar("KDB+").update(tabEditors, menuItem.getAction()); appMenubar.getMenu("KDB+").update(tabEditors, menuItem.getAction()); } else { if (menuItem.getAction().getClass() == ExtKit.ReplaceAction.class || menuItem.getAction() .getClass() == ActionFactory.RedoAction.class || menuItem.getAction() .getClass() == ActionFactory.UndoAction.class || menuItem.getAction() .getClass() == BaseKit.CopyAction.class || menuItem.getAction() .getClass() == BaseKit.PasteAction.class || menuItem.getAction() .getClass() == ExtKit.GotoAction.class || menuItem.getAction() .getClass() == BaseKit.SelectAllAction.class || menuItem.getAction() .getClass() == BaseKit.SelectLineAction.class || menuItem.getAction() .getClass() == BaseKit.CutAction.class) { appToolbar.getToolBar("Edit").update(tabEditors, menuItem.getAction()); if (menuItem.getAction().getClass() == ExtKit.GotoAction.class || menuItem.getAction() .getClass() == BaseKit.CopyAction.class || menuItem.getAction() .getClass() == BaseKit.SelectAllAction.class) { appMenubar.getMenu("Edit").update(tabEditors, menuItem.getAction(), true); } else { appMenubar.getMenu("Edit").update(tabEditors, menuItem.getAction()); } } } } } } } } } } } } if (event != null && event.getData() != -1 && event.getSource() instanceof EditorsTabbedPane && ((EditorsTabbedPane) event.getSource()).getEditor(event.getData()) != null) { ((EditorsTabbedPane) event.getSource()).getEditor(event.getData()).requestFocus(); } }
From source file:uk.ac.soton.mib104.t2.workbench.ui.ActivityConfigurationPanelWithInputPortAndOutputPortComponents.java
/** * Initializes the graphical user interface (GUI). * <p>/*from ww w .ja v a 2 s . c om*/ * Subclasses may refine the implementation of this method. */ protected void initGui() { this.setDoubleBuffered(false); this.setLayout(new BorderLayout()); tabbedPane.setBorder(BorderFactory.createEmptyBorder()); tabbedPane.addTab(defaultInputPortsTabText, defaultInputPortsTabIcon, inputPortsPane, defaultInputPortsTabTip); tabbedPane.addTab(defaultOutputPortsTabText, defaultOutputPortsTabIcon, outputPortsPane, defaultOutputPortsTabTip); this.add(tabbedPane, BorderLayout.CENTER); inputPortsPane.setBorder(BorderFactory.createEmptyBorder()); inputPortsPane.setLayout(new BorderLayout()); emptyInputPortsLabel.setHorizontalAlignment(JLabel.CENTER); emptyInputPortsLabel.setText(defaultEmptyInputPortsText); final JButton addInputPortButton = new JButton(); addInputPortButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { final String portName = nextPortName(defaultInputPortName, ActivityConfigurationPanelWithInputPortAndOutputPortComponents.this.getInputPortComponents() .keySet()); final IN_CONFIG inputPortConfigBean = ActivityConfigurationPanelWithInputPortAndOutputPortComponents.this .newInputPortConfiguration(); final IN_COMPONENT inputPortComponent = ActivityConfigurationPanelWithInputPortAndOutputPortComponents.this .toInputPortComponent(portName, inputPortConfigBean); inputPortsTabbedPane.addTab(portName, inputPortComponent); } }); addInputPortButton.setIcon(defaultAddInputPortButtonIcon); addInputPortButton.setText(defaultAddInputPortButtonText); addInputPortButton.setToolTipText(defaultAddInputPortButtonTip); inputPortsPane.add(emptyInputPortsLabel, BorderLayout.CENTER); inputPortsPane.add(addInputPortButton, BorderLayout.SOUTH); outputPortsPane.setBorder(BorderFactory.createEmptyBorder()); outputPortsPane.setLayout(new BorderLayout()); emptyOutputPortsLabel.setHorizontalAlignment(JLabel.CENTER); emptyOutputPortsLabel.setText(defaultEmptyOutputPortsText); final JButton addOutputPortButton = new JButton(); addOutputPortButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { final String portName = nextPortName(defaultOutputPortName, ActivityConfigurationPanelWithInputPortAndOutputPortComponents.this .getOutputPortComponents().keySet()); final OUT_CONFIG outputPortConfigBean = ActivityConfigurationPanelWithInputPortAndOutputPortComponents.this .newOutputPortConfiguration(); final OUT_COMPONENT outputPortComponent = ActivityConfigurationPanelWithInputPortAndOutputPortComponents.this .toOutputPortComponent(portName, outputPortConfigBean); outputPortsTabbedPane.addTab(portName, outputPortComponent); } }); addOutputPortButton.setIcon(defaultAddOutputPortButtonIcon); addOutputPortButton.setText(defaultAddOutputPortButtonText); addOutputPortButton.setToolTipText(defaultAddOutputPortButtonTip); outputPortsPane.add(emptyOutputPortsLabel, BorderLayout.CENTER); outputPortsPane.add(addOutputPortButton, BorderLayout.SOUTH); }
From source file:util.ui.UiUtilities.java
/** * Gibt einen Button mit Icon und Schrift zurck, der so initialisiert ist, * da man ihn gut fr Symbolleisten nutzen kann (Rahmen nur bei Rollover * sichtbar usw.).// w w w. j a va2 s . c o m * <P> * Wenn text und iconDateiname angegeben sind, dann wird text als TooltipText * gesetzt. * * @param text * Der Text des Buttons (Kann null sein, wenn der Button keinen Text * enthalten soll) * @param icon * Das Icon des Buttons (Kann ebenfalls null sein, wenn der Button * kein Icon enthalten soll). * @return button */ public static JButton createToolBarButton(String text, Icon icon) { final JButton btn; if (icon == null) { btn = new JButton(text); } else { btn = new JButton(icon); btn.setToolTipText(text); btn.setBorderPainted(false); btn.setMargin(ZERO_INSETS); btn.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { if (btn.isEnabled()) { btn.setBorderPainted(true); } } @Override public void mouseExited(MouseEvent e) { btn.setBorderPainted(false); } }); } btn.setFocusPainted(false); return btn; }
From source file:utybo.branchingstorytree.swing.editor.StoryNodesEditor.java
public StoryNodesEditor() { setLayout(new MigLayout("", "[:33%:300px][grow 150]", "[grow][]")); JScrollPane scrollPane = new JScrollPane(); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); add(scrollPane, "cell 0 0,grow"); jlist = new JList<>(); jlist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jlist.setCellRenderer(new SubstanceDefaultListCellRenderer() { @Override/*from www .j a v a2s. c om*/ public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") JList list, Object o, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = (JLabel) super.getListCellRendererComponent(list, o, index, isSelected, cellHasFocus); if (o instanceof StorySingleNodeEditor) { if (((StorySingleNodeEditor) o).getStatus() == Status.ERROR) label.setForeground(Color.RED.darker()); if (o instanceof StoryLogicalNodeEditor) label.setIcon(new ImageIcon(Icons.getImage("LogicalNode", 16))); else if (o instanceof StoryTextNodeEditor) label.setIcon(new ImageIcon(Icons.getImage("TextNode", 16))); else if (o instanceof StoryVirtualNodeEditor) label.setIcon(new ImageIcon(Icons.getImage("VirtualNode", 16))); } return label; } }); jlist.addListSelectionListener(e -> { if (jlist.getSelectedValue() instanceof JComponent) { container.removeAll(); container.add(jlist.getSelectedValue()); container.revalidate(); container.repaint(); } }); JScrollablePanel pan = new JScrollablePanel(new BorderLayout(0, 0)); jlist.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { scrollPane.revalidate(); pan.revalidate(); jlist.revalidate(); revalidate(); repaint(); } }); pan.setScrollableWidth(ScrollableSizeHint.FIT); pan.setScrollableHeight(ScrollableSizeHint.STRETCH); pan.add(jlist, BorderLayout.CENTER); scrollPane.setViewportView(pan); container = new JPanel(); add(container, "cell 1 0,grow"); container.setLayout(new BorderLayout(0, 0)); container.add(new JPanel(), BorderLayout.CENTER); // TODO JPanel panel = new JPanel(); add(panel, "cell 0 1 2 1,alignx leading,growy"); JButton btnAddNode = new JButton(Lang.get("editor.panel.add"), new ImageIcon(Icons.getImage("Add Subnode", 16))); btnAddNode.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { createMenu().show(btnAddNode, e.getX(), e.getY()); } }); panel.add(btnAddNode); JButton btnRemoveNode = new JButton(Lang.get("editor.panel.remove"), new ImageIcon(Icons.getImage("Delete Subnode", 16))); btnRemoveNode.addActionListener(e -> removeNode()); panel.add(btnRemoveNode); }
From source file:zxmax.tools.timerreview.gui.StartTimerWindow.java
private Component getPnlNewTimer() { setTitle(I18N.getLabel(getClass(), "window.title")); JPanel pnlNewTimer = new JPanel(); LayoutManager layout = new MigLayout("flowy", "[328.00][grow,fill]", "[][][][][]"); taFocusOn = new JTextArea(); taFocusOn.setWrapStyleWord(true);/*from w w w.java 2s. co m*/ JScrollPane spFocusOn = new JScrollPane(); tfTitle = new JTextField(30); JButton btnStart = new JButton(); pnlNewTimer.setLayout(layout); btnStart.setText(I18N.getLabel(this.getClass(), TAB_NEW_TIMER_BTN_START_LABEL)); taFocusOn.setColumns(20); taFocusOn.setForeground(new Color(0, 153, 0)); taFocusOn.setRows(5); taFocusOn.setTabSize(2); taFocusOn.setText(I18N.getLabel(this.getClass(), TAB_NEW_TIMER_FOCUS_ON_TEXT_AREA_TEXT)); taFocusOn.setToolTipText(I18N.getLabel(this.getClass(), TAB_NEW_TIMER_FOCUS_ON_TEXT_AREA_TOOL_TIP)); spFocusOn.setViewportView(taFocusOn); taFocusOn.getAccessibleContext().setAccessibleName("taFocusOn"); btnStart.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { storeDataAndStartTimer(); } }); btnStart.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent evt) { logger.debug(evt.getKeyCode() + ", " + evt.getKeyChar()); if (KeyEvent.VK_ENTER == evt.getKeyCode()) { storeDataAndStartTimer(); } } }); JLabel lblTitle = new JLabel(I18N.getLabel(this.getClass(), TAB_NEW_TIMER_TITLE_LABEL)); pnlNewTimer.add(lblTitle, "cell 0 0"); pnlNewTimer.add(tfTitle, "cell 0 1 2 1,growx"); JLabel lblFocusOn = new JLabel(I18N.getLabel(this.getClass(), TAB_NEW_TIMER_FOCUS_ON_LABEL)); pnlNewTimer.add(lblFocusOn, "cell 0 2"); pnlNewTimer.add(spFocusOn, "cell 0 3 2 1,growx"); pnlNewTimer.add(btnStart, "cell 0 4 2 1,growx"); Box horizontalBox = Box.createHorizontalBox(); pnlNewTimer.add(horizontalBox, "flowx,cell 1 0"); JLabel lblDurata = new JLabel(I18N.getLabel(this.getClass(), TAB_NEW_TIMER_DURATA_LABEL)); lblDurata.setHorizontalAlignment(SwingConstants.RIGHT); pnlNewTimer.add(lblDurata, "cell 1 0,alignx right"); lblDurata.setLabelFor(txtDurata); txtDurata = new JTextField("20"); txtDurata.setToolTipText(I18N.getLabel(this.getClass(), TAB_NEW_TIMER_DURATA_TOOL_TIP)); pnlNewTimer.add(txtDurata, "cell 1 0,alignx center"); txtDurata.setColumns(2); return pnlNewTimer; }