List of usage examples for javax.swing JList setSelectedIndex
@BeanProperty(bound = false, description = "The index of the selected cell.") public void setSelectedIndex(int index)
From source file:events.FocusEventDemo.java
public void addComponentsToPane(final Container pane) { GridBagLayout gridbag = new GridBagLayout(); pane.setLayout(gridbag);//w ww . ja v a 2 s. c o m GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; //Make column as wide as possible. JTextField textField = new JTextField("A TextField"); textField.setMargin(new Insets(0, 2, 0, 2)); textField.addFocusListener(this); gridbag.setConstraints(textField, c); add(textField); c.weightx = 0.1; //Widen every other column a bit, when possible. c.fill = GridBagConstraints.NONE; JLabel label = new JLabel("A Label"); label.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); label.addFocusListener(this); gridbag.setConstraints(label, c); add(label); String comboPrefix = "ComboBox Item #"; final int numItems = 15; Vector<String> vector = new Vector<String>(numItems); for (int i = 0; i < numItems; i++) { vector.addElement(comboPrefix + i); } JComboBox comboBox = new JComboBox(vector); comboBox.addFocusListener(this); gridbag.setConstraints(comboBox, c); add(comboBox); c.gridwidth = GridBagConstraints.REMAINDER; JButton button = new JButton("A Button"); button.addFocusListener(this); gridbag.setConstraints(button, c); add(button); c.weightx = 0.0; c.weighty = 0.1; c.fill = GridBagConstraints.BOTH; String listPrefix = "List Item #"; Vector<String> listVector = new Vector<String>(numItems); for (int i = 0; i < numItems; i++) { listVector.addElement(listPrefix + i); } JList list = new JList(listVector); list.setSelectedIndex(1); //It's easier to see the focus change //if an item is selected. list.addFocusListener(this); JScrollPane listScrollPane = new JScrollPane(list); gridbag.setConstraints(listScrollPane, c); add(listScrollPane); c.weighty = 1.0; //Make this row as tall as possible. c.gridheight = GridBagConstraints.REMAINDER; //Set up the area that reports focus-gained and focus-lost events. display = new JTextArea(); display.setEditable(false); //The setRequestFocusEnabled method prevents a //component from being clickable, but it can still //get the focus through the keyboard - this ensures //user accessibility. display.setRequestFocusEnabled(false); display.addFocusListener(this); JScrollPane displayScrollPane = new JScrollPane(display); gridbag.setConstraints(displayScrollPane, c); add(displayScrollPane); setPreferredSize(new Dimension(450, 450)); ((JPanel) pane).setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:FocusEventDemo.java
public void addComponentsToPane(final Container pane) { GridBagLayout gridbag = new GridBagLayout(); pane.setLayout(gridbag);//from ww w .j a va 2 s. c o m GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; // Make column as wide as possible. JTextField textField = new JTextField("A TextField"); textField.setMargin(new Insets(0, 2, 0, 2)); textField.addFocusListener(this); gridbag.setConstraints(textField, c); add(textField); c.weightx = 0.1; // Widen every other column a bit, when possible. c.fill = GridBagConstraints.NONE; JLabel label = new JLabel("A Label"); label.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); label.addFocusListener(this); gridbag.setConstraints(label, c); add(label); String comboPrefix = "ComboBox Item #"; final int numItems = 15; Vector<String> vector = new Vector<String>(numItems); for (int i = 0; i < numItems; i++) { vector.addElement(comboPrefix + i); } JComboBox comboBox = new JComboBox(vector); comboBox.addFocusListener(this); gridbag.setConstraints(comboBox, c); add(comboBox); c.gridwidth = GridBagConstraints.REMAINDER; JButton button = new JButton("A Button"); button.addFocusListener(this); gridbag.setConstraints(button, c); add(button); c.weightx = 0.0; c.weighty = 0.1; c.fill = GridBagConstraints.BOTH; String listPrefix = "List Item #"; Vector<String> listVector = new Vector<String>(numItems); for (int i = 0; i < numItems; i++) { listVector.addElement(listPrefix + i); } JList list = new JList(listVector); list.setSelectedIndex(1); // It's easier to see the focus change // if an item is selected. list.addFocusListener(this); JScrollPane listScrollPane = new JScrollPane(list); gridbag.setConstraints(listScrollPane, c); add(listScrollPane); c.weighty = 1.0; // Make this row as tall as possible. c.gridheight = GridBagConstraints.REMAINDER; // Set up the area that reports focus-gained and focus-lost events. display = new JTextArea(); display.setEditable(false); // The setRequestFocusEnabled method prevents a // component from being clickable, but it can still // get the focus through the keyboard - this ensures // user accessibility. display.setRequestFocusEnabled(false); display.addFocusListener(this); JScrollPane displayScrollPane = new JScrollPane(display); gridbag.setConstraints(displayScrollPane, c); add(displayScrollPane); setPreferredSize(new Dimension(450, 450)); ((JPanel) pane).setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:FocusEventDemo.java
public FocusEventDemo() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; //Make column as wide as possible. JTextField textField = new JTextField("A TextField"); textField.setMargin(new Insets(0, 2, 0, 2)); textField.addFocusListener(this); gridbag.setConstraints(textField, c); add(textField);/* ww w . j av a 2s . c o m*/ c.weightx = 0.1; //Widen every other column a bit, when possible. c.fill = GridBagConstraints.NONE; JLabel label = new JLabel("A Label"); label.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); label.addFocusListener(this); gridbag.setConstraints(label, c); add(label); String comboPrefix = "ComboBox Item #"; final int numItems = 15; Vector vector = new Vector(numItems); for (int i = 0; i < numItems; i++) { vector.addElement(comboPrefix + i); } JComboBox comboBox = new JComboBox(vector); comboBox.addFocusListener(this); gridbag.setConstraints(comboBox, c); add(comboBox); c.gridwidth = GridBagConstraints.REMAINDER; JButton button = new JButton("A Button"); button.addFocusListener(this); gridbag.setConstraints(button, c); add(button); c.weightx = 0.0; c.weighty = 0.1; c.fill = GridBagConstraints.BOTH; String listPrefix = "List Item #"; Vector listVector = new Vector(numItems); for (int i = 0; i < numItems; i++) { listVector.addElement(listPrefix + i); } JList list = new JList(listVector); list.setSelectedIndex(1); //It's easier to see the focus change //if an item is selected. list.addFocusListener(this); JScrollPane listScrollPane = new JScrollPane(list); //We want to prevent the list's scroll bars //from getting the focus - even with the keyboard. //Note that in general we prefer setRequestFocusable //over setFocusable for reasons of accessibility, //but this is to work around bug #4866958. listScrollPane.getVerticalScrollBar().setFocusable(false); listScrollPane.getHorizontalScrollBar().setFocusable(false); gridbag.setConstraints(listScrollPane, c); add(listScrollPane); c.weighty = 1.0; //Make this row as tall as possible. c.gridheight = GridBagConstraints.REMAINDER; //Set up the area that reports focus-gained and focus-lost events. display = new JTextArea(); display.setEditable(false); //The method setRequestFocusEnabled prevents a //component from being clickable, but it can still //get the focus through the keyboard - this ensures //user accessibility. display.setRequestFocusEnabled(false); display.addFocusListener(this); JScrollPane displayScrollPane = new JScrollPane(display); //Work around for bug #4866958. displayScrollPane.getHorizontalScrollBar().setFocusable(false); displayScrollPane.getVerticalScrollBar().setFocusable(false); gridbag.setConstraints(displayScrollPane, c); add(displayScrollPane); setPreferredSize(new Dimension(450, 450)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:Main.java
public Main() { setLayout(new GridLayout(1, 2)); String[] numbers = { "one", "two", "three", "four", "five", "six", "seven" }; JList<String> list = new JList<>(numbers); list.setVisibleRowCount(1);//w ww. ja v a 2 s .c o m list.addListSelectionListener(this); JScrollPane s = new JScrollPane(list); s.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); s.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); add(s); list.setSelectedIndex(3); }
From source file:net.sf.jabref.gui.openoffice.OOBibBase.java
public static XTextDocument selectComponent(List<XTextDocument> list) throws UnknownPropertyException, WrappedTargetException, IndexOutOfBoundsException { String[] values = new String[list.size()]; int ii = 0;/*from www . j a va 2 s. c o m*/ for (XTextDocument doc : list) { values[ii] = String.valueOf(OOUtil.getProperty(doc.getCurrentController().getFrame(), "Title")); ii++; } JList<String> sel = new JList<>(values); sel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); sel.setSelectedIndex(0); int ans = JOptionPane.showConfirmDialog(null, new JScrollPane(sel), Localization.lang("Select document"), JOptionPane.OK_CANCEL_OPTION); if (ans == JOptionPane.OK_OPTION) { return list.get(sel.getSelectedIndex()); } else { return null; } }
From source file:net.sf.jabref.openoffice.AutoDetectPaths.java
private boolean autoDetectPaths() { if (OS.WINDOWS) { List<File> progFiles = findProgramFilesDir(); File sOffice = null;//from w ww .j a v a 2s . co m List<File> sofficeFiles = new ArrayList<>(); for (File dir : progFiles) { if (fileSearchCancelled) { return false; } sOffice = findFileDir(dir, "soffice.exe"); if (sOffice != null) { sofficeFiles.add(sOffice); } } if (sOffice == null) { JOptionPane.showMessageDialog(parent, Localization.lang( "Unable to autodetect OpenOffice/LibreOffice installation. Please choose the installation directory manually."), Localization.lang("Could not find OpenOffice/LibreOffice installation"), JOptionPane.INFORMATION_MESSAGE); JFileChooser jfc = new JFileChooser(new File("C:\\")); jfc.setDialogType(JFileChooser.OPEN_DIALOG); jfc.setFileFilter(new javax.swing.filechooser.FileFilter() { @Override public boolean accept(File file) { return file.isDirectory(); } @Override public String getDescription() { return Localization.lang("Directories"); } }); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.showOpenDialog(parent); if (jfc.getSelectedFile() != null) { sOffice = jfc.getSelectedFile(); } } if (sOffice == null) { return false; } if (sofficeFiles.size() > 1) { // More than one file found DefaultListModel<File> mod = new DefaultListModel<>(); for (File tmpfile : sofficeFiles) { mod.addElement(tmpfile); } JList<File> fileList = new JList<>(mod); fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fileList.setSelectedIndex(0); FormBuilder b = FormBuilder.create() .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 4dlu, pref")); b.add(Localization.lang("Found more than one OpenOffice/LibreOffice executable.")).xy(1, 1); b.add(Localization.lang("Please choose which one to connect to:")).xy(1, 3); b.add(fileList).xy(1, 5); int answer = JOptionPane.showConfirmDialog(null, b.getPanel(), Localization.lang("Choose OpenOffice/LibreOffice executable"), JOptionPane.OK_CANCEL_OPTION); if (answer == JOptionPane.CANCEL_OPTION) { return false; } else { sOffice = fileList.getSelectedValue(); } } else { sOffice = sofficeFiles.get(0); } return setupPreferencesForOO(sOffice.getParentFile(), sOffice, "soffice.exe"); } else if (OS.OS_X) { File rootDir = new File("/Applications"); File[] files = rootDir.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory() && ("OpenOffice.org.app".equals(file.getName()) || "LibreOffice.app".equals(file.getName()))) { rootDir = file; break; } } } File sOffice = findFileDir(rootDir, SOFFICE_BIN); if (fileSearchCancelled) { return false; } if (sOffice == null) { return false; } else { return setupPreferencesForOO(rootDir, sOffice, SOFFICE_BIN); } } else { // Linux: String usrRoot = "/usr/lib"; File inUsr = findFileDir(new File(usrRoot), SOFFICE); if (fileSearchCancelled) { return false; } if (inUsr == null) { inUsr = findFileDir(new File("/usr/lib64"), SOFFICE); if (inUsr != null) { usrRoot = "/usr/lib64"; } } if (fileSearchCancelled) { return false; } File inOpt = findFileDir(new File("/opt"), SOFFICE); if (fileSearchCancelled) { return false; } if ((inUsr != null) && (inOpt == null)) { return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN); } else if (inOpt != null) { if (inUsr == null) { return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN); } else { // Found both JRadioButton optRB = new JRadioButton(inOpt.getPath(), true); JRadioButton usrRB = new JRadioButton(inUsr.getPath(), false); ButtonGroup bg = new ButtonGroup(); bg.add(optRB); bg.add(usrRB); FormBuilder b = FormBuilder.create() .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 2dlu, pref ")); b.add(Localization.lang( "Found more than one OpenOffice/LibreOffice executable. Please choose which one to connect to:")) .xy(1, 1); b.add(optRB).xy(1, 3); b.add(usrRB).xy(1, 5); int answer = JOptionPane.showConfirmDialog(null, b.getPanel(), Localization.lang("Choose OpenOffice/LibreOffice executable"), JOptionPane.OK_CANCEL_OPTION); if (answer == JOptionPane.CANCEL_OPTION) { return false; } if (optRB.isSelected()) { return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN); } else { return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN); } } } } return false; }
From source file:net.sf.jabref.gui.preftabs.PreferencesDialog.java
public PreferencesDialog(JabRefFrame parent) { super(parent, Localization.lang("JabRef preferences"), false); JabRefPreferences prefs = JabRefPreferences.getInstance(); frame = parent;/*from w w w . j av a 2 s . c o m*/ main = new JPanel(); JPanel mainPanel = new JPanel(); JPanel lower = new JPanel(); getContentPane().setLayout(new BorderLayout()); getContentPane().add(mainPanel, BorderLayout.CENTER); getContentPane().add(lower, BorderLayout.SOUTH); final CardLayout cardLayout = new CardLayout(); main.setLayout(cardLayout); List<PrefsTab> tabs = new ArrayList<>(); tabs.add(new GeneralTab(prefs)); tabs.add(new NetworkTab(prefs)); tabs.add(new FileTab(frame, prefs)); tabs.add(new FileSortTab(prefs)); tabs.add(new EntryEditorPrefsTab(frame, prefs)); tabs.add(new GroupsPrefsTab(prefs)); tabs.add(new AppearancePrefsTab(prefs)); tabs.add(new ExternalTab(frame, this, prefs)); tabs.add(new TablePrefsTab(prefs)); tabs.add(new TableColumnsTab(prefs, parent)); tabs.add(new LabelPatternPrefTab(prefs, parent.getCurrentBasePanel())); tabs.add(new PreviewPrefsTab(prefs)); tabs.add(new NameFormatterTab(prefs)); tabs.add(new ImportSettingsTab(prefs)); tabs.add(new XmpPrefsTab(prefs)); tabs.add(new AdvancedTab(prefs)); // add all tabs tabs.forEach(tab -> main.add((Component) tab, tab.getTabName())); mainPanel.setBorder(BorderFactory.createEtchedBorder()); String[] tabNames = tabs.stream().map(PrefsTab::getTabName).toArray(String[]::new); JList<String> chooser = new JList<>(tabNames); chooser.setBorder(BorderFactory.createEtchedBorder()); // Set a prototype value to control the width of the list: chooser.setPrototypeCellValue("This should be wide enough"); chooser.setSelectedIndex(0); chooser.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // Add the selection listener that will show the correct panel when // selection changes: chooser.addListSelectionListener(e -> { if (e.getValueIsAdjusting()) { return; } String o = chooser.getSelectedValue(); cardLayout.show(main, o); }); JPanel buttons = new JPanel(); buttons.setLayout(new GridLayout(4, 1)); buttons.add(importPreferences, 0); buttons.add(exportPreferences, 1); buttons.add(showPreferences, 2); buttons.add(resetPreferences, 3); JPanel westPanel = new JPanel(); westPanel.setLayout(new BorderLayout()); westPanel.add(chooser, BorderLayout.CENTER); westPanel.add(buttons, BorderLayout.SOUTH); mainPanel.setLayout(new BorderLayout()); mainPanel.add(main, BorderLayout.CENTER); mainPanel.add(westPanel, BorderLayout.WEST); JButton ok = new JButton(Localization.lang("OK")); JButton cancel = new JButton(Localization.lang("Cancel")); ok.addActionListener(new OkAction()); CancelAction cancelAction = new CancelAction(); cancel.addActionListener(cancelAction); lower.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); ButtonBarBuilder buttonBarBuilder = new ButtonBarBuilder(lower); buttonBarBuilder.addGlue(); buttonBarBuilder.addButton(ok); buttonBarBuilder.addButton(cancel); buttonBarBuilder.addGlue(); // Key bindings: KeyBinder.bindCloseDialogKeyToCancelAction(this.getRootPane(), cancelAction); // Import and export actions: exportPreferences.setToolTipText(Localization.lang("Export preferences to file")); exportPreferences.addActionListener(e -> { String filename = FileDialogs.getNewFile(frame, new File(System.getProperty("user.home")), Collections.singletonList(".xml"), JFileChooser.SAVE_DIALOG, false); if (filename == null) { return; } File file = new File(filename); if (!file.exists() || (JOptionPane.showConfirmDialog(PreferencesDialog.this, Localization.lang("'%0' exists. Overwrite file?", file.getName()), Localization.lang("Export preferences"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)) { try { prefs.exportPreferences(filename); } catch (JabRefException ex) { LOGGER.warn(ex.getMessage(), ex); JOptionPane.showMessageDialog(PreferencesDialog.this, ex.getLocalizedMessage(), Localization.lang("Export preferences"), JOptionPane.ERROR_MESSAGE); } } }); importPreferences.setToolTipText(Localization.lang("Import preferences from file")); importPreferences.addActionListener(e -> { String filename = FileDialogs.getNewFile(frame, new File(System.getProperty("user.home")), Collections.singletonList(".xml"), JFileChooser.OPEN_DIALOG, false); if (filename != null) { try { prefs.importPreferences(filename); updateAfterPreferenceChanges(); JOptionPane.showMessageDialog(PreferencesDialog.this, Localization.lang("You must restart JabRef for this to come into effect."), Localization.lang("Import preferences"), JOptionPane.WARNING_MESSAGE); } catch (JabRefException ex) { LOGGER.warn(ex.getMessage(), ex); JOptionPane.showMessageDialog(PreferencesDialog.this, ex.getLocalizedMessage(), Localization.lang("Import preferences"), JOptionPane.ERROR_MESSAGE); } } }); showPreferences.addActionListener( e -> new PreferencesFilterDialog(new JabRefPreferencesFilter(Globals.prefs), frame) .setVisible(true)); resetPreferences.addActionListener(e -> { if (JOptionPane.showConfirmDialog(PreferencesDialog.this, Localization.lang("Are you sure you want to reset all settings to default values?"), Localization.lang("Reset preferences"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { try { prefs.clear(); JOptionPane.showMessageDialog(PreferencesDialog.this, Localization.lang("You must restart JabRef for this to come into effect."), Localization.lang("Reset preferences"), JOptionPane.WARNING_MESSAGE); } catch (BackingStoreException ex) { LOGGER.warn(ex.getMessage(), ex); JOptionPane.showMessageDialog(PreferencesDialog.this, ex.getLocalizedMessage(), Localization.lang("Reset preferences"), JOptionPane.ERROR_MESSAGE); } updateAfterPreferenceChanges(); } }); setValues(); pack(); }
From source file:com.kstenschke.copypastestack.ToolWindow.java
private void initItemsPreview() { this.form.labelPreviewImage.setText(""); this.form.panelPreviewImage.setVisible(false); this.form.scrollPanePreview.setVisible(true); // Install listener to update shown preview from current clipboard final FocusListenerViewClipboard focusListenerViewClipboard = new FocusListenerViewClipboard(this); this.form.listPreview.addFocusListener(focusListenerViewClipboard); this.form.checkBoxScale50Percent .addChangeListener(new ChangeListenerResizePreview(focusListenerViewClipboard)); this.form.buttonRefreshPreview.addMouseListener(new MouseListenerBase(StaticTexts.INFO_REFRESH_PREVIEW)); final JList listPreview = this.form.listPreview; this.form.buttonRefreshPreview.addActionListener(new ActionListener() { @Override//from w w w. j a v a 2 s .c o m public void actionPerformed(ActionEvent e) { focusListenerViewClipboard.updateClipboardPreview(); listPreview.requestFocusInWindow(); listPreview.setSelectedIndex(0); } }); // Install items listener to update shown preview from stacked items this.form.listClipItems.addListSelectionListener(new ListSelectionListenerItemsList(this)); // Add popup listener this.form.textPanePreview.addMouseListener(new PopupPreview(this).getPopupListener()); }
From source file:com.projity.pm.graphic.chart.ChartLegend.java
JList getListInstance(boolean cost) { final JList list = new JList() { // do not want to update the UI. see below also private static final long serialVersionUID = 1L; public void updateUI() { if (!Environment.isNewLook()) super.updateUI(); }// ww w . j a v a2 s .c om }; if (Environment.isNewLook()) // The PLAF can override the custom renderer. This avoids that list.setUI(new BasicListUI()); list.setSelectionMode(DefaultListSelectionModel.MULTIPLE_INTERVAL_SELECTION); list.setCellRenderer(new ListRenderer()); setListFields(list, cost); if (!simple) { list.setSelectedIndex(0); // start off with first choice selected list.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (chartInfo.isRestoring()) // don't want to listen if updating from workspace return; if (e.getValueIsAdjusting() == false) { chartInfo.setTraces(list.getSelectedValues()); } } }); } return list; }
From source file:com.rapidminer.gui.new_plotter.gui.ColorSchemeDialog.java
/** * @return// www.j a v a2s .c o m */ private JPanel createColorCategoriesPanel() { JPanel categoryColorsConfigurationPanel = new JPanel(new GridBagLayout()); categoryColorsConfigurationPanel.setPreferredSize(new Dimension(180, 200)); GridBagConstraints itemConstraint = new GridBagConstraints(); JLabel categoryColorsLabel = new ResourceLabel( "plotter.configuration_dialog.color_scheme_dialog.category_colors"); { itemConstraint.fill = GridBagConstraints.HORIZONTAL; itemConstraint.anchor = GridBagConstraints.WEST; itemConstraint.gridwidth = GridBagConstraints.RELATIVE; itemConstraint.insets = new Insets(0, 5, 5, 5); itemConstraint.weightx = 1.0; categoryColorsConfigurationPanel.add(categoryColorsLabel, itemConstraint); } // add button panel { JPanel buttonPanel = new JPanel(new GridBagLayout()); // remove scheme button { removeCategoryColorButton = new JButton(new ResourceAction(true, "plotter.configuration_dialog.color_scheme_dialog.remove_category_color_button") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { removeSelectedColorAction(); } }); itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.RELATIVE; itemConstraint.fill = GridBagConstraints.NONE; buttonPanel.add(removeCategoryColorButton, itemConstraint); } { addCategoryButton = new JButton(new ResourceAction(true, "plotter.configuration_dialog.color_scheme_dialog.add_category_color_button") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { Color oldColor = Color.white; Color newSchemeColor = createColorDialog(oldColor); if (newSchemeColor != null && !newSchemeColor.equals(oldColor)) { addColorAction(newSchemeColor); } } }); itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.fill = GridBagConstraints.NONE; buttonPanel.add(addCategoryButton, itemConstraint); } itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.fill = GridBagConstraints.NONE; itemConstraint.anchor = GridBagConstraints.EAST; itemConstraint.insets = new Insets(0, 5, 5, 5); categoryColorsConfigurationPanel.add(buttonPanel, itemConstraint); } { JPanel categoryListPanel = new JPanel(new GridBagLayout()); // add list of categorie colors { colorList = new JList<Color>(nominalColorListModel); categoryColorsLabel.setLabelFor(colorList); colorList.setCellRenderer(new ColorListCellRenderer()); colorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); MouseAdapter ma = new MouseAdapter() { private void myPopupEvent(MouseEvent e) { int x = e.getX(); int y = e.getY(); JList<?> list = (JList<?>) e.getSource(); list.setSelectedIndex(list.locationToIndex(e.getPoint())); Color selectedColor = (Color) list.getSelectedValue(); if (selectedColor == null) { return; } removeMenuItem.setEnabled(nominalColorListModel.getSize() > 2); popupMenu.show(list, x, y); } @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { myPopupEvent(e); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { myPopupEvent(e); } } }; colorList.addMouseListener(ma); colorList.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { return; // Nothing to be done } @Override public void keyReleased(KeyEvent e) { return; // Nothing to be done } @Override public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_DELETE) { if (nominalColorListModel.getSize() > 2) { removeSelectedColorAction(); } } if (key == KeyEvent.VK_F2) { replaceSelectedColorAction(); } if (key == KeyEvent.VK_UP && SwingTools.isControlOrMetaDown(e)) { moveSelectedColorUpAction(); } if (key == KeyEvent.VK_DOWN && SwingTools.isControlOrMetaDown(e)) { moveSelectedColorDownAction(); } } }); colorListScrollPane = new JScrollPane(colorList); colorListScrollPane.setPreferredSize(new Dimension(170, 200)); colorListScrollPane.setMaximumSize(new Dimension(170, 200)); colorListScrollPane.setMinimumSize(new Dimension(170, 180)); colorListScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); colorListScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); itemConstraint = new GridBagConstraints(); itemConstraint.fill = GridBagConstraints.BOTH; itemConstraint.weightx = 0.0; itemConstraint.weighty = 0.5; itemConstraint.gridwidth = GridBagConstraints.RELATIVE; categoryListPanel.add(colorListScrollPane, itemConstraint); } // add up/down button panel { JPanel upAndDownButtonPanel = new JPanel(new GridBagLayout()); // add up button { JButton upButton = new JButton( new ResourceAction(true, "plotter.configuration_dialog.move_color_up") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { moveSelectedColorUpAction(); } }); itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.weightx = 0; itemConstraint.weighty = 0; itemConstraint.fill = GridBagConstraints.NONE; itemConstraint.insets = new Insets(0, 2, 0, 12); upAndDownButtonPanel.add(upButton, itemConstraint); } // add down button { JButton downButton = new JButton( new ResourceAction(true, "plotter.configuration_dialog.move_color_down") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { moveSelectedColorDownAction(); } }); itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.weightx = 0; itemConstraint.weighty = 0; itemConstraint.fill = GridBagConstraints.NONE; itemConstraint.insets = new Insets(0, 2, 0, 12); upAndDownButtonPanel.add(downButton, itemConstraint); } // add spacer panel { JPanel spacer = new JPanel(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.weightx = 0; itemConstraint.weighty = 1; itemConstraint.fill = GridBagConstraints.VERTICAL; upAndDownButtonPanel.add(spacer, itemConstraint); } itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.weightx = 1; itemConstraint.weighty = 1; itemConstraint.fill = GridBagConstraints.VERTICAL; categoryListPanel.add(upAndDownButtonPanel, itemConstraint); } itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.weightx = 1; itemConstraint.weighty = 1; itemConstraint.fill = GridBagConstraints.BOTH; categoryColorsConfigurationPanel.add(categoryListPanel, itemConstraint); } return categoryColorsConfigurationPanel; }