List of usage examples for javax.swing ListSelectionModel addListSelectionListener
void addListSelectionListener(ListSelectionListener x);
From source file:SelectionExample.java
public SelectionExample() { super("Selection Model Test"); setSize(450, 350);// www. j a v a2 s . co m setDefaultCloseOperation(EXIT_ON_CLOSE); TableModel tm = new AbstractTableModel() { // We'll create a simple multiplication table to serve as a // noneditable // table with several rows and columns public int getRowCount() { return 10; } public int getColumnCount() { return 10; } public Object getValueAt(int r, int c) { return "" + (r + 1) * (c + 1); } }; final JTable jt = new JTable(tm); JScrollPane jsp = new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); // Now set up our selection controls JPanel controlPanel, buttonPanel, columnPanel, rowPanel; buttonPanel = new JPanel(); final JCheckBox cellBox, columnBox, rowBox; cellBox = new JCheckBox("Cells", jt.getCellSelectionEnabled()); columnBox = new JCheckBox("Columns", jt.getColumnSelectionAllowed()); rowBox = new JCheckBox("Rows", jt.getRowSelectionAllowed()); cellBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { jt.setCellSelectionEnabled(cellBox.isSelected()); columnBox.setSelected(jt.getColumnSelectionAllowed()); rowBox.setSelected(jt.getRowSelectionAllowed()); } }); columnBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { jt.setColumnSelectionAllowed(columnBox.isSelected()); cellBox.setSelected(jt.getCellSelectionEnabled()); } }); rowBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { jt.setRowSelectionAllowed(rowBox.isSelected()); cellBox.setSelected(jt.getCellSelectionEnabled()); } }); buttonPanel.add(new JLabel("Selections allowed:")); buttonPanel.add(cellBox); buttonPanel.add(columnBox); buttonPanel.add(rowBox); columnPanel = new JPanel(); ListSelectionModel csm = jt.getColumnModel().getSelectionModel(); JLabel columnCounter = new JLabel("(Selected Column Indices Go Here)"); csm.addListSelectionListener(new SelectionDebugger(columnCounter, csm)); columnPanel.add(new JLabel("Selected columns:")); columnPanel.add(columnCounter); rowPanel = new JPanel(); ListSelectionModel rsm = jt.getSelectionModel(); JLabel rowCounter = new JLabel("(Selected Row Indices Go Here)"); rsm.addListSelectionListener(new SelectionDebugger(rowCounter, rsm)); rowPanel.add(new JLabel("Selected rows:")); rowPanel.add(rowCounter); controlPanel = new JPanel(new GridLayout(0, 1)); controlPanel.add(buttonPanel); controlPanel.add(columnPanel); controlPanel.add(rowPanel); getContentPane().add(controlPanel, BorderLayout.SOUTH); }
From source file:com.dnsoft.inmobiliaria.controllers.ConsultaCCPropietariosController.java
final void configuraTblPropietarios() { ((DefaultTableCellRenderer) view.tblPropietario.getTableHeader().getDefaultRenderer()) .setHorizontalAlignment(SwingConstants.CENTER); listPropietarios = new ArrayList<>(); tableModelPropietarios = new PropietariosTableModel(listPropietarios); view.tblPropietario.setModel(tableModelPropietarios); view.tblPropietario.setRowHeight(25); view.tblPropietario.getColumn("Activo").setMaxWidth(0); view.tblPropietario.getColumn("Activo").setMinWidth(0); view.tblPropietario.getColumn("Activo").setPreferredWidth(0); view.tblPropietario.getColumn("Activo").setWidth(0); view.tblPropietario.setDefaultRenderer(Object.class, new TableRendererColorActivo(2)); ListSelectionModel listModel = view.tblPropietario.getSelectionModel(); listModel.addListSelectionListener(new ListSelectionListener() { @Override//from ww w.jav a2 s . com public void valueChanged(ListSelectionEvent lse) { if (view.tblPropietario.getSelectedRow() != -1) { view.btnCuenta.setEnabled(true); view.btnPropietario.setEnabled(true); } else { view.btnCuenta.setEnabled(false); view.btnPropietario.setEnabled(false); } } }); view.tblPropietario.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent me) { if (me.getClickCount() == 2) { detallesCCPropietario(); } } }); }
From source file:simx.profiler.info.application.MessagesInfoTopComponent.java
public MessagesInfoTopComponent() { initComponents();// w w w .j a v a 2 s.c om setName(Bundle.CTL_MessagesInfoTopComponent()); setToolTipText(Bundle.HINT_MessagesInfoTopComponent()); this.content = new InstanceContent(); this.associateLookup(new AbstractLookup(this.content)); this.profilingData = ProfilingData.getLoadedProfilingData(); this.messagesDataSet = new DefaultPieDataset(); this.createPieChart(this.messagesDataSet, this.graphicalPanel); final ListSelectionModel listSelectionModel = this.messageTypeInformationTable.getSelectionModel(); listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listSelectionModel.addListSelectionListener((final ListSelectionEvent e) -> { if (messageTypeInformationTable.getSelectedRow() != -1) { final List<Map.Entry<MessageType, Integer>> data = new ArrayList<>( communicationData.getCommunicationData().entrySet()); final MessageType messageType = data.get(messageTypeInformationTable.getSelectedRow()).getKey(); content.set(Collections.singleton(messageType), null); } }); }
From source file:com.funambol.email.admin.user.ResultSearchUserPanel.java
/** * Set up graphic elements for this panel. * * @throws Exception if error occures during creation of the panel *///from w ww . j av a 2 s . c om private void init() throws Exception { // create objects to display this.setLayout(new BorderLayout()); this.setBorder(BorderFactory.createEmptyBorder()); // create a model for the user table and pass it to the JTable object model = new UserTableModel(); table = new JTable(model); table.setShowGrid(true); table.setAutoscrolls(true); table.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION); JScrollPane scrollpane = new JScrollPane(table); table.setPreferredScrollableViewportSize(new Dimension(800, 200)); table.setFont(GuiFactory.defaultTableFont); table.getTableHeader().setFont(GuiFactory.defaultTableHeaderFont); this.add(scrollpane, BorderLayout.CENTER); // // Select user. // table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); ListSelectionModel rowSM = table.getSelectionModel(); rowSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { if (event.getValueIsAdjusting()) { return; } ListSelectionModel lsm = (ListSelectionModel) event.getSource(); if (lsm.isSelectionEmpty()) { selectedUser = null; } else { int selectedRow = lsm.getMinSelectionIndex(); selectedUser = users[selectedRow]; } } }); rowSM.clearSelection(); table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent event) { if (event.getClickCount() < 2) { return; } // // If the selected user is already associated to an account // then insertion process can't go on. // String userName = selectedUser.getUsername(); String value[] = new String[] { userName }; WhereClause wc = new WhereClause("username", value, WhereClause.OPT_EQ, true); MailServerAccount[] tmp = null; try { tmp = WSDao.getAccounts(wc); } catch (Exception e) { } if (tmp.length > 0) { StringBuilder sb = new StringBuilder("The user "); sb.append(userName).append(" is already associated to an account"); Object[] options = { "OK" }; JOptionPane.showOptionDialog(null, sb.toString(), "Warning", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); } else { // // Go to next step. // step.goToNextStep(); } } }); }
From source file:io.bibleget.BibleGetFrame.java
public void updateDynamicInformation() throws ClassNotFoundException { prepareDynamicInformation();/* ww w . j av a2 s .co m*/ jList1.setModel(new DefaultEventListModel<>(versionsByLang)); jList1.setCellRenderer(new VersionCellRenderer()); jList1.setSelectionModel(new DisabledItemSelectionModel()); ListSelectionModel listSelectionModel = jList1.getSelectionModel(); listSelectionModel.addListSelectionListener(new SharedListSelectionHandler()); jList1.setSelectedIndices(indices); jScrollPane2.setViewportView(jList1); jScrollPane2.revalidate(); }
From source file:com.digitalgeneralists.assurance.ui.components.ResultsPanel.java
private void initializeComponent() { if (!this.initialized) { GridBagLayout gridbag = new GridBagLayout(); this.setLayout(gridbag); ((DefaultTableCellRenderer) resultsTable.getTableHeader().getDefaultRenderer()) .setHorizontalAlignment(JLabel.CENTER); this.resultsTable.setRowHeight(150); ListSelectionModel selectionModel = this.resultsTable.getSelectionModel(); selectionModel.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { applicationDelegate.fireEvent(new SetScanResultsMenuStateEvent(false)); resultsTable.editCellAt(resultsTable.getSelectedRow(), 0); }// w w w. ja v a2 s . c o m }); GridBagConstraints resultsLabelConstraints = new GridBagConstraints(); resultsLabelConstraints.anchor = GridBagConstraints.WEST; resultsLabelConstraints.fill = GridBagConstraints.BOTH; resultsLabelConstraints.gridx = 0; resultsLabelConstraints.gridy = 0; resultsLabelConstraints.weightx = 1.0; resultsLabelConstraints.weighty = 0.1; resultsLabelConstraints.gridheight = 1; resultsLabelConstraints.gridwidth = 1; resultsLabelConstraints.insets = new Insets(5, 5, 5, 5); this.progressIndicatorConstraints.anchor = GridBagConstraints.WEST; this.progressIndicatorConstraints.fill = GridBagConstraints.BOTH; this.progressIndicatorConstraints.gridx = 0; this.progressIndicatorConstraints.gridy = 1; this.progressIndicatorConstraints.weightx = 1.0; this.progressIndicatorConstraints.weighty = 0.1; this.progressIndicatorConstraints.gridheight = 1; this.progressIndicatorConstraints.gridwidth = 1; this.progressIndicatorConstraints.insets = new Insets(5, 5, 5, 5); this.progressIndicator.setIndeterminate(true); this.resultsListConstraints.anchor = GridBagConstraints.WEST; this.resultsListConstraints.fill = GridBagConstraints.BOTH; this.resultsListConstraints.gridx = 0; this.resultsListConstraints.gridy = 2; this.resultsListConstraints.weightx = 1.0; this.resultsListConstraints.weighty = 0.9; this.resultsListConstraints.gridheight = 1; this.resultsListConstraints.gridwidth = 1; this.resultsListConstraints.insets = new Insets(5, 5, 5, 5); this.add(this.resultsLabel, resultsLabelConstraints); this.add(this.resultsScrollPane, this.resultsListConstraints); this.addAncestorListener(new AncestorListener() { public void ancestorAdded(AncestorEvent event) { resultsTable.setDefaultRenderer(ComparisonResult.class, comparisonResultListRenderer); resultsTable.setDefaultEditor(ComparisonResult.class, comparisonResultListRenderer); applicationDelegate.addEventObserver(ScanStartedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.addEventObserver(ComparisonResultAddedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.addEventObserver(ScanResultsLoadedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.addEventObserver(SelectedScanChangedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.addEventObserver(ScanCompletedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.addEventObserver(ScanProgressEvent.class, (IEventObserver) event.getSource()); applicationDelegate.addEventObserver(ResultMergeCompletedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.addEventObserver(ScanMergeStartedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.addEventObserver(ScanMergeProgressEvent.class, (IEventObserver) event.getSource()); applicationDelegate.addEventObserver(ScanMergeCompletedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.addEventObserver(DeletedItemRestoreCompletedEvent.class, (IEventObserver) event.getSource()); } public void ancestorRemoved(AncestorEvent event) { applicationDelegate.removeEventObserver(ScanStartedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.removeEventObserver(ComparisonResultAddedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.removeEventObserver(ScanResultsLoadedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.removeEventObserver(SelectedScanChangedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.removeEventObserver(ScanCompletedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.removeEventObserver(ScanProgressEvent.class, (IEventObserver) event.getSource()); applicationDelegate.removeEventObserver(ResultMergeCompletedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.removeEventObserver(ScanMergeStartedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.removeEventObserver(ScanMergeProgressEvent.class, (IEventObserver) event.getSource()); applicationDelegate.removeEventObserver(ScanMergeCompletedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.removeEventObserver(DeletedItemRestoreCompletedEvent.class, (IEventObserver) event.getSource()); } public void ancestorMoved(AncestorEvent event) { } }); this.initialized = true; } }
From source file:io.bibleget.BibleGetFrame.java
/** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor./*from w ww. ja v a 2 s .c om*/ */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jScrollPane2 = new javax.swing.JScrollPane(); jList1 = new javax.swing.JList(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle(__("Insert quote from input window")); setBounds(frameLeft, frameTop, frameWidth, frameHeight); setType(java.awt.Window.Type.UTILITY); jLabel1.setLabelFor(jTextField1); jLabel1.setText(__("Type the desired Bible Quote using standard notation:")); jTextField1.setToolTipText("e.g. Mt1,1-10"); jLabel2.setBackground(new java.awt.Color(204, 255, 204)); jLabel2.setFont(new java.awt.Font("Times New Roman", 2, 11)); // NOI18N jLabel2.setForeground(new java.awt.Color(51, 51, 51)); jLabel2.setText(__("(e.g. Mt 1,1-10.12-15;5,3-4;Jn 3,16)")); jLabel4.setText(__("Choose version (or versions)")); jList1.setModel(new DefaultEventListModel<>(versionsByLang)); jList1.setCellRenderer(new VersionCellRenderer()); jList1.setSelectionModel(new DisabledItemSelectionModel()); ListSelectionModel listSelectionModel = jList1.getSelectionModel(); listSelectionModel.addListSelectionListener(new SharedListSelectionHandler()); jList1.setSelectedIndices(indices); jScrollPane2.setViewportView(jList1); jButton1.setText(__("Send query")); jButton1.setToolTipText(__("Sends the request to the server and returns the results to the document.")); jButton1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jButton1MouseClicked(evt); } }); jButton2.setText(__("Cancel")); jButton2.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jButton2MouseClicked(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGap(57, 57, 57) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jScrollPane2) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE) .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(57, 57, 57))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(40, 40, 40).addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(1, 1, 1).addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(jLabel4) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1).addComponent(jButton2)) .addGap(39, 39, 39))); pack(); }
From source file:cz.muni.fi.javaseminar.kafa.bookregister.gui.MainWindow.java
private void initAuthorsTable() { authorsTable.getColumnModel().getColumn(2) .setCellEditor(new DatePickerCellEditor(new SimpleDateFormat("dd. MM. yyyy"))); authorsTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() { @Override/*from w ww . j a v a2 s . c o m*/ public Component getTableCellRendererComponent(JTable jtable, Object value, boolean selected, boolean hasFocus, int row, int column) { if (value instanceof Date) { // You could use SimpleDateFormatter instead value = new SimpleDateFormat("dd. MM. yyyy").format(value); } return super.getTableCellRendererComponent(jtable, value, selected, hasFocus, row, column); } }); authorsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); ListSelectionModel selectionModel = authorsTable.getSelectionModel(); selectionModel.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { DefaultListSelectionModel source = (DefaultListSelectionModel) e.getSource(); if (source.getMinSelectionIndex() >= 0) { authorsTableModel.setCurrentSlectedIndex(source.getMinSelectionIndex()); } if (!e.getValueIsAdjusting()) { booksTableModel.setAuthorIndex(source.getMinSelectionIndex()); } } }); authorsTable.getColumnModel().getColumn(2) .setCellEditor(new DatePickerCellEditor(new SimpleDateFormat("dd. MM. yyyy"))); authorsTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable jtable, Object value, boolean selected, boolean hasFocus, int row, int column) { if (value instanceof Date) { // You could use SimpleDateFormatter instead value = new SimpleDateFormat("dd. MM. yyyy").format(value); } return super.getTableCellRendererComponent(jtable, value, selected, hasFocus, row, column); } }); JPopupMenu authorsPopupMenu = new JPopupMenu(); JMenuItem deleteItem = new JMenuItem("Delete"); authorsPopupMenu.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { int rowAtPoint = authorsTable.rowAtPoint( SwingUtilities.convertPoint(authorsPopupMenu, new Point(0, 0), authorsTable)); if (rowAtPoint > -1) { authorsTable.setRowSelectionInterval(rowAtPoint, rowAtPoint); authorsTableModel.setCurrentSlectedIndex(rowAtPoint); } } }); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // TODO Auto-generated method stub } @Override public void popupMenuCanceled(PopupMenuEvent e) { // TODO Auto-generated method stub } }); deleteItem.addActionListener(new ActionListener() { private Author author; @Override public void actionPerformed(ActionEvent e) { new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { author = authorsTableModel.getAuthors().get(authorsTable.getSelectedRow()); log.debug("Deleting author: " + author.getFirstname() + " " + author.getSurname() + " from database."); authorManager.deleteAuthor(author); return null; } @Override protected void done() { try { get(); } catch (InterruptedException | ExecutionException e) { if (e.getCause() instanceof DataIntegrityViolationException) { JOptionPane.showMessageDialog(MainWindow.this, "Couldn't delete author; there are still some books assigned to him.", "Error", JOptionPane.ERROR_MESSAGE); } log.error("There was an exception thrown during deletion author: " + author.getFirstname() + " " + author.getSurname(), e); return; } updateModel(); } }.execute(); } }); authorsPopupMenu.add(deleteItem); authorsTable.setComponentPopupMenu(authorsPopupMenu); }
From source file:net.sf.keystore_explorer.gui.dialogs.extensions.DViewExtensions.java
private void initComponents() { ExtensionsTableModel extensionsTableModel = new ExtensionsTableModel(); jtExtensions = new JKseTable(extensionsTableModel); TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(extensionsTableModel); sorter.setComparator(2, new ObjectIdComparator()); jtExtensions.setRowSorter(sorter);/* w w w . java 2 s . c o m*/ jtExtensions.setShowGrid(false); jtExtensions.setRowMargin(0); jtExtensions.getColumnModel().setColumnMargin(0); jtExtensions.getTableHeader().setReorderingAllowed(false); jtExtensions.setAutoResizeMode(JKseTable.AUTO_RESIZE_ALL_COLUMNS); jtExtensions.setRowHeight(Math.max(18, jtExtensions.getRowHeight())); for (int i = 0; i < jtExtensions.getColumnCount(); i++) { TableColumn column = jtExtensions.getColumnModel().getColumn(i); column.setHeaderRenderer( new ExtensionsTableHeadRend(jtExtensions.getTableHeader().getDefaultRenderer())); column.setCellRenderer(new ExtensionsTableCellRend()); } TableColumn criticalCol = jtExtensions.getColumnModel().getColumn(0); criticalCol.setResizable(false); criticalCol.setMinWidth(28); criticalCol.setMaxWidth(28); criticalCol.setPreferredWidth(28); ListSelectionModel selectionModel = jtExtensions.getSelectionModel(); selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); selectionModel.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { try { CursorUtil.setCursorBusy(DViewExtensions.this); updateExtensionValue(); } finally { CursorUtil.setCursorFree(DViewExtensions.this); } } } }); jspExtensionsTable = PlatformUtil.createScrollPane(jtExtensions, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); jspExtensionsTable.getViewport().setBackground(jtExtensions.getBackground()); jpExtensionsTable = new JPanel(new BorderLayout(5, 5)); jpExtensionsTable.setPreferredSize(new Dimension(500, 200)); jpExtensionsTable.add(jspExtensionsTable, BorderLayout.CENTER); jpExtensionValue = new JPanel(new BorderLayout(5, 5)); jlExtensionValue = new JLabel(res.getString("DViewExtensions.jlExtensionValue.text")); jpExtensionValue.add(jlExtensionValue, BorderLayout.NORTH); jepExtensionValue = new JEditorPane(); jepExtensionValue.setFont(new Font(Font.MONOSPACED, Font.PLAIN, LnfUtil.getDefaultFontSize())); jepExtensionValue.setEditable(false); jepExtensionValue.setToolTipText(res.getString("DViewExtensions.jtaExtensionValue.tooltip")); // JGoodies - keep uneditable color same as editable jepExtensionValue.putClientProperty("JTextArea.infoBackground", Boolean.TRUE); // for displaying URLs in extensions as clickable links jepExtensionValue.setContentType("text/html"); jepExtensionValue.addHyperlinkListener(this); // use default font and foreground color from the component jepExtensionValue.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); jspExtensionValue = PlatformUtil.createScrollPane(jepExtensionValue, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); jpExtensionValueTextArea = new JPanel(new BorderLayout(5, 5)); jpExtensionValueTextArea.setPreferredSize(new Dimension(500, 200)); jpExtensionValueTextArea.add(jspExtensionValue, BorderLayout.CENTER); jpExtensionValue.add(jpExtensionValueTextArea, BorderLayout.CENTER); jbAsn1 = new JButton(res.getString("DViewExtensions.jbAsn1.text")); PlatformUtil.setMnemonic(jbAsn1, res.getString("DViewExtensions.jbAsn1.mnemonic").charAt(0)); jbAsn1.setToolTipText(res.getString("DViewExtensions.jbAsn1.tooltip")); jbAsn1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { try { CursorUtil.setCursorBusy(DViewExtensions.this); asn1DumpPressed(); } finally { CursorUtil.setCursorFree(DViewExtensions.this); } } }); jpExtensionValueAsn1 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); jpExtensionValueAsn1.add(jbAsn1); jpExtensionValue.add(jpExtensionValueAsn1, BorderLayout.SOUTH); jpExtensions = new JPanel(new GridLayout(2, 1, 5, 5)); jpExtensions.setBorder(new CompoundBorder(new EmptyBorder(5, 5, 5, 5), new CompoundBorder(new EtchedBorder(), new EmptyBorder(5, 5, 5, 5)))); jpExtensions.add(jpExtensionsTable); jpExtensions.add(jpExtensionValue); jbOK = new JButton(res.getString("DViewExtensions.jbOK.text")); jbOK.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { okPressed(); } }); jpOK = PlatformUtil.createDialogButtonPanel(jbOK, false); extensionsTableModel.load(extensions); if (extensionsTableModel.getRowCount() > 0) { jtExtensions.changeSelection(0, 0, false, false); } getContentPane().add(jpExtensions, BorderLayout.CENTER); getContentPane().add(jpOK, BorderLayout.SOUTH); setResizable(false); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent evt) { closeDialog(); } }); getRootPane().setDefaultButton(jbOK); pack(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { jbOK.requestFocus(); } }); }
From source file:com.dbschools.quickquiz.client.giver.MainWindow.java
private void addListeners() { takerTableDisplay.addTableKeyListener(new KeyAdapter() { @Override//from w w w.ja va2 s. c o m public void keyPressed(KeyEvent e) { char keyChar = e.getKeyChar(); if (Character.isDigit(keyChar) && e.isControlDown()) { awardPoints(Integer.parseInt(Character.toString(keyChar))); } } }); final ListSelectionModel takerTableSelectionModel = takerTableDisplay.getSelectionModel(); takerTableSelectionModel.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { btnAwardPoints.setEnabled(!takerTableSelectionModel.isSelectionEmpty()); } }); countdownMeter.addCountdownFinishListener(new CountdownFinishListener() { public void countdownFinished() { SwingUtilities.invokeLater(new Runnable() { public void run() { btnSendQuestion.setEnabled(true); } }); } }); }