private void init() { model.addViewerModelListener(this); list = new JList(); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (list.getSelectedValue() != null) { model.selectNode((Node) list.getSelectedValue(), EvaluationResultsPanel.this); } } }); add(new JScrollPane(list), BorderLayout.CENTER); }
public JList<?> getFontSizeList() { if (fontSizeList == null) { fontSizeList = new JList<Object>(this.fontSizeStrings); fontSizeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fontSizeList.addListSelectionListener(new ListSelectionHandler(getFontSizeTextField())); fontSizeList.setSelectedIndex(0); fontSizeList.setFont(DEFAULT_FONT); fontSizeList.setFocusable(false); } return fontSizeList; }
private JComponent createXPathResultPanel() { xpathResults.addElement("No XPath results yet, run an XPath Query first."); xpathResultList.setBorder(BorderFactory.createLineBorder(Color.black)); xpathResultList.setFixedCellWidth(300); xpathResultList.setCellRenderer(new ASTListCellRenderer()); xpathResultList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); xpathResultList.getSelectionModel().addListSelectionListener(new ASTSelectionListener()); JScrollPane scrollPane = new JScrollPane(); scrollPane.getViewport().setView(xpathResultList); return scrollPane; }
final JList fileList = new JList(new Vector<>(files)); fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); MouseListener mouseListener = new MouseAdapter() { public void mouseClicked(MouseEvent e) { fileList.addMouseListener(mouseListener); final JScrollPane scroll = new JScrollPane(fileList);
JPanel contentPanel = getContentPanel(); JPanel buttonsPanel = new JPanel(new GridLayout(3, 1)); contentPanel.add(buttonsPanel, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); JPanel modesPanel = new JPanel(new GridLayout(4, 1)); contentPanel.add(modesPanel, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); imagesPanel = new JPanel(new GridBagLayout()); contentPanel.add(imagesPanel, new GridBagConstraints(2, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); imageListModel = new DefaultListModel<String>(); imageList = new JList<String>(imageListModel); imageList.setFixedCellWidth(250); imageList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); imagesPanel.add(imageList, new GridBagConstraints(0, 0, 1, 3, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); list.setLayoutOrientation(JList.VERTICAL); list.setVisibleRowCount(-1); // -1 = display max items in space available list.ensureIndexIsVisible(lastNdx); JPanel panel = new JPanel(); panel.add(scrollPane);
public JList getWindowList() { if (windowList == null) { windowList = new JList(); windowList.addMouseListener(this); windowList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } return windowList; }
private void initServerList() { serverList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); serverList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { boolean enabled = !serverList.isSelectionEmpty(); firePropertyChange(OK_ENABLED, !enabled, enabled); } } ); serverList.setCellRenderer(new ServersRenderer()); }
private JComponent createQuickOpenPanel(JList<QuickOpenAction> listPanel, String title, List<File> fileList) { listPanel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listPanel.addListSelectionListener(event -> { if (event.getValueIsAdjusting()) { return; } int selectedIndex = listPanel.getSelectedIndex(); if (selectedIndex < 0) { return; } QuickOpenAction action = listPanel.getModel().getElementAt(selectedIndex); action.actionPerformed(new ActionEvent(listPanel, -1, null)); }); refreshQuickOpenPanel(listPanel, fileList); JScrollPane scrollPane = new JScrollPane(listPanel); scrollPane.getVerticalScrollBar().setUnitIncrement(25); scrollPane.setMinimumSize(new Dimension(100, 80)); // Size fits into screen resolution 1024*768 scrollPane.setPreferredSize(new Dimension(180, 200)); JPanel titlePanel = new JPanel(new BorderLayout()); titlePanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); JLabel titleLabel = new JLabel(title); titleLabel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); titlePanel.add(titleLabel, BorderLayout.NORTH); titlePanel.add(scrollPane, BorderLayout.CENTER); return titlePanel; }
list = new JList<String>(classesList); list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); list.setLayoutOrientation(JList.VERTICAL_WRAP); list.setVisibleRowCount(-1); JScrollPane listScroller = new JScrollPane(list, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
JPanel contentPanel = getContentPanel(); JPanel buttonsPanel = new JPanel(new GridLayout(3, 1)); contentPanel.add(buttonsPanel, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); JPanel modesPanel = new JPanel(new GridLayout(4, 1)); contentPanel.add(modesPanel, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); imagesPanel = new JPanel(new GridBagLayout()); contentPanel.add(imagesPanel, new GridBagConstraints(2, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); imageListModel = new DefaultListModel<String>(); imageList = new JList<String>(imageListModel); imageList.setFixedCellWidth(250); imageList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); imagesPanel.add(imageList, new GridBagConstraints(0, 0, 1, 3, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
public JList<?> getFontStyleList() { if (fontStyleList == null) { fontStyleList = new JList<Object>(getFontStyleNames()); fontStyleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fontStyleList.addListSelectionListener(new ListSelectionHandler(getFontStyleTextField())); fontStyleList.setSelectedIndex(0); fontStyleList.setFocusable(false); fontStyleList.setCellRenderer(new DefaultListCellRenderer() { /** * */ private static final long serialVersionUID = -3904668242514776943L; public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value instanceof String) { renderer.setText((String) value); renderer.setFont( new Font(DEFAULT_FONT.getName(), FONT_STYLE_CODES[index], DEFAULT_FONT.getSize() + 2)); } else { renderer.setText(""); } return renderer; } }); } return fontStyleList; }
private JComponent createXPathResultPanel() { xpathResults.addElement("No XPath results yet, run an XPath Query first."); xpathResultList.setBorder(BorderFactory.createLineBorder(Color.black)); xpathResultList.setFixedCellWidth(300); xpathResultList.setCellRenderer(new ASTListCellRenderer()); xpathResultList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); xpathResultList.getSelectionModel().addListSelectionListener(new ASTSelectionListener()); JScrollPane scrollPane = new JScrollPane(); scrollPane.getViewport().setView(xpathResultList); return scrollPane; }
JList list; DefaultListModel listModel; listModel = new DefaultListModel(); listModel.addElement("word1"); listModel.addElement("word2"); listModel.addElement("word3"); //Create the list and put it in a scroll pane. list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0); list.addListSelectionListener(this); list.setVisibleRowCount(5); JScrollPane listScrollPane = new JScrollPane(list);
JPanel jp_north = new JPanel(); jp_north.setLayout(new FlowLayout(FlowLayout.LEFT)); JLabel jl = new JLabel("Font for Request Body & Response Body"); JPanel jp_center = new JPanel(); jp_center.setLayout(new GridLayout(1, 2)); String[] fontFamilyNames = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); jl_font = new JList<String>(fontFamilyNames); jl_font.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jl_font.addListSelectionListener(previewListner); JScrollPane jsp_font = new JScrollPane(jl_font); jsp_font.setPreferredSize(d); jp_center.add(jsp_font); String fontSizes[] = { "8", "10", "11", "12", "14", "16", "18", "20", "24", "30", "36", "40", "48", "60", "72" }; jl_fontSize = new JList<String>(fontSizes); jl_fontSize.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jl_fontSize.addListSelectionListener(previewListner); JScrollPane jsp_fontSize = new JScrollPane(jl_fontSize); jsp_fontSize.setPreferredSize(d); jp_center.add(jsp_fontSize); JPanel jp_south = new JPanel(); jp_south.setLayout(new FlowLayout(FlowLayout.CENTER)); jp_south.add(jl_preview);
import javax.swing.*; import java.io.*; import java.util.ArrayList; class MultiSelectList { public static void main(String[] args) throws Exception { File f = new File("MultiSelectList.java"); InputStream is = new FileInputStream(f); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); final ArrayList<String> lines = new ArrayList<String>(); String line = br.readLine(); while (line!=null) { lines.add(line); line = br.readLine(); } SwingUtilities.invokeLater(new Runnable() { public void run() { JList list = new JList(lines.toArray()); list.setSelectionMode( ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); int[] select = {19, 20, 22}; list.setSelectedIndices(select); JOptionPane.showMessageDialog(null, new JScrollPane(list)); } }); } }
private void createSortPane(){ sortPane = new JPanel(); sortPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Tracks order")); sortPane.setLayout(new BoxLayout(sortPane,BoxLayout.X_AXIS)); tracksData[i++] = f.getName(); tracksJList = new JList<>(tracksData); tracksJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); tracksJList.setSelectedIndex(0); buttons = new JPanel(); downButton = new JButton(); downButton.setIcon(ARROW_DOWN);
public JList<?> getFontFamilyList() { if (fontNameList == null) { fontNameList = new JList<Object>(getFontFamilies()); fontNameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fontNameList.addListSelectionListener(new ListSelectionHandler(getFontFamilyTextField())); fontNameList.setSelectedIndex(0); // Draw Fonts fontNameList.setCellRenderer(new DefaultListCellRenderer() { /** * */ private static final long serialVersionUID = -6753380853569310954L; public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value instanceof String) { renderer.setText((String) value); renderer.setFont(new Font((String) value, DEFAULT_FONT.getStyle(), DEFAULT_FONT.getSize() + 2)); } else { renderer.setText(""); } return renderer; } }); fontNameList.setFocusable(false); } return fontNameList; }
public void initTypeList() { getTokenTypeList().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } if (getTokenTypeList().getSelectedValue() == null) { reset(); } else { bind((String) getTokenTypeList().getSelectedValue()); } } }); getTokenTypeList().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); }
public DFAPanel() { super(); setLayout(new BorderLayout()); JPanel leftPanel = new JPanel(); nodeList = new JList(nodes); nodeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); nodeList.setFixedCellWidth(150); nodeList.setBorder(BorderFactory.createLineBorder(Color.black)); nodeList.addListSelectionListener(this); leftPanel.add(nodeList); add(leftPanel, BorderLayout.WEST); dfaCanvas = new DFACanvas(); dfaCanvas.setBackground(Color.WHITE); dfaCanvas.setPreferredSize(new Dimension(900, 1400)); JScrollPane scrollPane = new JScrollPane(dfaCanvas); add(scrollPane, BorderLayout.CENTER); }