List of usage examples for javax.swing JTable JTable
public JTable(TableModel dm)
JTable
that is initialized with dm
as the data model, a default column model, and a default selection model. From source file:io.heming.accountbook.ui.MainFrame.java
public MainFrame() throws Exception { categoryFacade = new CategoryFacade(); recordFacade = new RecordFacade(); builder = new Pages.Builder(); builder.order("id", false); pages = builder.make();//from w ww .jav a2s .c om date_chooser_visible = false; disable = false; // Create widgets model = new TableModel(); table = new JTable(model) { /** * tip. * * @param evt * @return */ @Override public String getToolTipText(MouseEvent evt) { String tip = null; java.awt.Point point = evt.getPoint(); int row = rowAtPoint(point); int col = columnAtPoint(point); Rectangle bounds = getCellRect(row, col, false); Component comp = prepareRenderer(getCellRenderer(row, col), row, col); try { if (comp.getPreferredSize().width > bounds.width) { tip = getValueAt(row, col).toString(); } } catch (RuntimeException e) { //catch null pointer exception if mouse is over an empty line } return tip; } }; if (pages.hasNext()) { model.setRecords(pages.next()); } // ? table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); TableColumnModel columnModel = table.getColumnModel(); columnModel.getColumn(0).setPreferredWidth(80); columnModel.getColumn(1).setPreferredWidth(160); columnModel.getColumn(2).setPreferredWidth(80); columnModel.getColumn(3).setPreferredWidth(100); columnModel.getColumn(4).setPreferredWidth(100); columnModel.getColumn(5).setPreferredWidth(360); // Layout JScrollPane pane = new JScrollPane(table); add(pane, BorderLayout.CENTER); table.getTableHeader().setReorderingAllowed(false); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // table header table.getTableHeader().addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int col = table.columnAtPoint(e.getPoint()); String name = table.getColumnName(col); // TODO } }); // ? addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { quit(); } }); categories = categoryFacade.listBySale(); initMenuBar(); initToolBar(); initStatusBar(); initTablePopupMenu(); searchRecords(); setIconImage(new ImageIcon(getClass().getResource("64.png")).getImage()); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); setTitle(""); setSize(860, 620); }
From source file:logdruid.ui.RecordingList.java
/** * Create the panel.//from w w w. j a v a 2s .c o m */ public RecordingList(final Repository rep) { if (Preferences.getPreference("timings").equals("true")) { header = (String[]) new String[] { "name", "regexp", "type", "active", "success time", "failed time", "match attempt", "success match" }; } else { header = (String[]) new String[] { "name", "regexp", "type", "active" }; } records = rep.getRecordings(); // Collections.sort(records); Iterator it = records.iterator(); while (it.hasNext()) { Recording record = (Recording) it.next(); stats = DataVault.getRecordingStats(record.getName()); if (stats != null) { data.add(new Object[] { record.getName(), record.getRegexp(), record.getType(), record.getIsActive(), stats[0], stats[1], stats[2], stats[3] }); } else { data.add(new Object[] { record.getName(), record.getRegexp(), record.getType(), record.getIsActive(), 0, 0, 0, 0 }); } } repository = rep; model = new MyTableModel2(data, header); JPanel panel_1 = new JPanel(); GridBagConstraints gbc_panel_1 = new GridBagConstraints(); gbc_panel_1.fill = GridBagConstraints.BOTH; gbc_panel_1.insets = new Insets(5, 0, 5, 5); gbc_panel_1.gridx = 1; gbc_panel_1.gridy = 0; panel_1.setLayout(new BorderLayout(0, 0)); table = new JTable(model); JScrollPane scrollPane = new JScrollPane(table); int column; panel_1.add(scrollPane); table.setPreferredScrollableViewportSize(new Dimension(0, 150)); table.setFillsViewportHeight(true); // Set up column sizes. initColumnSizes(table); table.setAutoCreateRowSorter(true); // RowSorter sorter = table.getRowSorter(); // sorter.setSortKeys(Arrays.asList(new RowSorter.SortKey(0, SortOrder.ASCENDING))); if (model.getRowCount() > 0) { table.getRowSorter().toggleSortOrder(0); table.getRowSorter().toggleSortOrder(2); } table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { int selectedRow = ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1); ; logger.info("ListSelectionListener - selectedRow: " + selectedRow); if (selectedRow >= 0) { if (jPanelDetail != null) { logger.info("ListSelectionListener - valueChanged"); jPanelDetail.removeAll(); recEditor = getEditor(repository.getRecording(selectedRow)); if (recEditor != null) { jPanelDetail.add(recEditor, BorderLayout.CENTER); } jPanelDetail.revalidate(); } } } }); JPanel panel = new JPanel(); FlowLayout flowLayout = (FlowLayout) panel.getLayout(); flowLayout.setAlignment(FlowLayout.LEFT); flowLayout.setVgap(2); flowLayout.setHgap(2); panel_1.add(panel, BorderLayout.SOUTH); JButton btnNewMeta = new JButton("New Meta"); panel.add(btnNewMeta); btnNewMeta.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { int rowCount = table.getRowCount(); jPanelDetail.removeAll(); Recording re = new MetadataRecording("name", "regex", "example line", "", true, null); recEditor = new MetadataRecordingEditor(thiis, repository, "the line", "regex", (MetadataRecording) re); jPanelDetail.add(recEditor, BorderLayout.CENTER); repository.addRecording(re); model.addRow( new Object[] { re.getName(), re.getRegexp(), re.getType(), re.getIsActive(), 0, 0, 0, 0 }); model.fireTableRowsInserted(rowCount, rowCount); table.setRowSelectionInterval(rowCount, rowCount); logger.info("New record - row count : " + rowCount); } }); JButton btnDuplicate = new JButton("Duplicate"); btnDuplicate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int rowCount = table.getRowCount(); int selectRow = ((table.getSelectedRow() != -1) ? table.getSelectedRow() : -1); int selectedRow = ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1); repository.addRecording( repository.getRecording(table.convertRowIndexToModel(table.getSelectedRow())).duplicate()); model.fireTableRowsInserted(rowCount, rowCount); table.setRowSelectionInterval(selectRow, selectRow); } }); JButton btnNewStat = new JButton("New Stat"); btnNewStat.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int rowCount = table.getRowCount(); jPanelDetail.removeAll(); Recording re = new StatRecording("name", "regex", "example line", "", true, null); recEditor = new StatRecordingEditor(thiis, repository, "the line", "regex", (StatRecording) re); jPanelDetail.add(recEditor, BorderLayout.CENTER); repository.addRecording(re); model.addRow( new Object[] { re.getName(), re.getRegexp(), re.getType(), re.getIsActive(), 0, 0, 0, 0 }); model.fireTableRowsInserted(rowCount, rowCount); table.setRowSelectionInterval(rowCount, rowCount); logger.info("New record - row count : " + rowCount); } }); panel.add(btnNewStat); JButton btnNewEvent = new JButton("New Event"); btnNewEvent.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int rowCount = table.getRowCount(); logger.info("table.getRowCount()" + table.getRowCount()); jPanelDetail.removeAll(); Recording re = new EventRecording("name", "regex", "example line", "", true, null); recEditor = new EventRecordingEditor(thiis, repository, "the line", "regex", (EventRecording) re); jPanelDetail.add(recEditor, BorderLayout.CENTER); repository.addRecording(re); model.addRow( new Object[] { re.getName(), re.getRegexp(), re.getType(), re.getIsActive(), 0, 0, 0, 0 }); model.fireTableRowsInserted(rowCount, rowCount); table.setRowSelectionInterval(rowCount, rowCount); logger.info("New record - row count : " + rowCount); } }); panel.add(btnNewEvent); panel.add(btnDuplicate); JButton btnDelete = new JButton("Delete"); btnDelete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int rowCount = table.getRowCount(); int selectedRow = ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1); ; int realSelectedRow = table.getSelectedRow(); logger.info("selectedRow : " + selectedRow + ", row count: " + table.getRowCount()); if (rowCount != 0) { repository.deleteRecording(selectedRow); model.fireTableRowsDeleted(selectedRow, selectedRow); // table.remove(selectedRow); if (realSelectedRow != -1) { if (realSelectedRow != 0) table.setRowSelectionInterval(realSelectedRow - 1, realSelectedRow - 1); else if (realSelectedRow > 0) table.setRowSelectionInterval(realSelectedRow, realSelectedRow); else if (rowCount > 1) table.setRowSelectionInterval(0, 0); } /* if (table.getRowCount() > 0) { if (selectedRow == table.getRowCount()) { table.setRowSelectionInterval(selectedRow - 1, selectedRow - 1); } else table.setRowSelectionInterval(selectedRow, selectedRow); }*/ } } }); panel.add(btnDelete); setLayout(new BorderLayout(0, 0)); JSplitPane splitPane = new JSplitPane(); splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); add(splitPane, BorderLayout.CENTER); jPanelDetail = new JPanel(); GridBagConstraints gbc_jPanelDetail = new GridBagConstraints(); gbc_jPanelDetail.insets = new Insets(0, 0, 0, 5); gbc_jPanelDetail.fill = GridBagConstraints.BOTH; gbc_jPanelDetail.gridx = 1; gbc_jPanelDetail.gridy = 4; splitPane.setBottomComponent(jPanelDetail); splitPane.setTopComponent(panel_1); jPanelDetail.setLayout(new BorderLayout(0, 0)); if (repository.getRecordingCount() > 0) { //recEditor = getEditor(repository.getRecording(0)); //jPanelDetail.add(recEditor, BorderLayout.CENTER); table.setRowSelectionInterval(0, 0); } jPanelDetail.revalidate(); }
From source file:edu.ku.brc.specify.config.init.secwiz.UserPanel.java
/** * /* ww w . ja va 2s . com*/ */ protected void createUI() { dbList = new JList(new DefaultListModel()); otherDBList = new JList(new DefaultListModel()); userModel = new UserTableModel(null); userTable = new JTable(userModel); CellConstraints cc = new CellConstraints(); saveBtn = UIHelper.createButton("Save"); mkKeysBtn = UIHelper.createButton("Make Keys"); copyKeyBtn = UIHelper.createButton("Copy Master Key"); sendKeysBtn = UIHelper.createButton("Send Keys"); showKeysBtn = UIHelper.createButton("Show Summary"); printKeysBtn = UIHelper.createButton("Print"); btns = new JButton[] { saveBtn, sendKeysBtn, copyKeyBtn, showKeysBtn, printKeysBtn }; String colDef = UIHelper.createDuplicateJGoodiesDef("p", "8px", btns.length); PanelBuilder btnPB = new PanelBuilder(new FormLayout("f:p:g," + colDef, "p")); int x = 2; for (JButton b : btns) { btnPB.add(b, cc.xy(x, 1)); x += 2; } saveBtn.setEnabled(false); copyKeyBtn.setEnabled(false); label = UIHelper.createLabel("", SwingConstants.CENTER); gainAccessBtn = UIHelper.createIconBtn("Unmap", "", null); loseAccessBtn = UIHelper.createIconBtn("Map", "", null); PanelBuilder bpb = new PanelBuilder(new FormLayout("p", "f:p:g,p,8px,p,f:p:g")); bpb.add(gainAccessBtn, cc.xy(1, 2)); bpb.add(loseAccessBtn, cc.xy(1, 4)); PanelBuilder tpb = new PanelBuilder(new FormLayout("f:p:g,10px,p,10px,f:p:g", "p,4px,f:p:g")); tpb.add(UIHelper.createI18NLabel("MSTR_HAS_PERM", SwingConstants.CENTER), cc.xy(1, 1)); tpb.add(otherDBLbl = UIHelper.createI18NLabel("MSTR_HAS_NOPERM", SwingConstants.CENTER), cc.xy(5, 1)); tpb.add(dbScrollPane = UIHelper.createScrollPane(dbList), cc.xy(1, 3)); tpb.add(bpb.getPanel(), cc.xy(3, 3)); tpb.add(odbScrollPane = UIHelper.createScrollPane(otherDBList), cc.xy(5, 3)); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,p", "f:p:g,20px,p,8px,p,4px,f:p:g,4px,p,20px,p"), this); sendKeysBtn.setVisible(false); int y = 1; pb.add(tpb.getPanel(), cc.xyw(1, y, 2)); y += 2; y += 2; pb.add(label, cc.xyw(1, y, 2)); y += 2; pb.add(userScrollPane = UIHelper.createScrollPane(userTable), cc.xyw(1, y, 2)); y += 2; pb.add(btnPB.getPanel(), cc.xy(2, y)); y += 2; pb.addSeparator("", cc.xyw(1, y, 2)); y += 2; dbList.setVisibleRowCount(8); otherDBList.setVisibleRowCount(8); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Dimension size = userTable.getPreferredScrollableViewportSize(); size.height = 10 * userTable.getRowHeight(); userTable.setPreferredScrollableViewportSize(size); } }); updateBtnUI(false); dbList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { loadData(false); gainAccessBtn.setEnabled(otherDBList.getSelectedIndex() > -1); loseAccessBtn.setEnabled(dbList.getSelectedIndex() > -1); } } }); userTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { doUserSelected(); } } }); saveBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveUserData(); } }); sendKeysBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { sendKeys(); } }); mkKeysBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { makeKeys(); } }); copyKeyBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int inx = userTable.getSelectedRow(); if (inx > -1) { String masterKey = userModel.getUserData().get(inx).getMasterKey(); UIHelper.setTextToClipboard(masterKey); } } }); showKeysBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { displayData(); } }); printKeysBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { printUserData(); } }); gainAccessBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { changeMasterAccess(true); } }); loseAccessBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { changeMasterAccess(false); } }); otherDBList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { otherDBName = (String) otherDBList.getSelectedValue(); gainAccessBtn.setEnabled(otherDBList.getSelectedIndex() > -1); loseAccessBtn.setEnabled(dbList.getSelectedIndex() > -1); } } }); }
From source file:net.sf.jabref.gui.search.SearchResultsDialog.java
private void init(String title) { diag = new JDialog(frame, title, false); int activePreview = Globals.prefs.getInt(JabRefPreferences.ACTIVE_PREVIEW); String layoutFile = activePreview == 0 ? Globals.prefs.get(JabRefPreferences.PREVIEW_0) : Globals.prefs.get(JabRefPreferences.PREVIEW_1); preview = new PreviewPanel(null, null, layoutFile); sortedEntries = new SortedList<>(entries, new EntryComparator(false, true, FieldName.AUTHOR)); model = (DefaultEventTableModel<BibEntry>) GlazedListsSwing .eventTableModelWithThreadProxyList(sortedEntries, new EntryTableFormat()); entryTable = new JTable(model); GeneralRenderer renderer = new GeneralRenderer(Color.white); entryTable.setDefaultRenderer(JLabel.class, renderer); entryTable.setDefaultRenderer(String.class, renderer); setWidths();/*from www. ja v a 2 s . c om*/ TableComparatorChooser<BibEntry> tableSorter = TableComparatorChooser.install(entryTable, sortedEntries, AbstractTableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD); setupComparatorChooser(tableSorter); JScrollPane sp = new JScrollPane(entryTable); final DefaultEventSelectionModel<BibEntry> selectionModel = (DefaultEventSelectionModel<BibEntry>) GlazedListsSwing .eventSelectionModelWithThreadProxyList(sortedEntries); entryTable.setSelectionModel(selectionModel); selectionModel.getSelected().addListEventListener(new EntrySelectionListener()); entryTable.addMouseListener(new TableClickListener()); contentPane.setTopComponent(sp); contentPane.setBottomComponent(preview); // Key bindings: AbstractAction closeAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { diag.dispose(); } }; ActionMap am = contentPane.getActionMap(); InputMap im = contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); am.put("close", closeAction); entryTable.getActionMap().put("copy", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (!selectionModel.getSelected().isEmpty()) { List<BibEntry> bes = selectionModel.getSelected(); TransferableBibtexEntry trbe = new TransferableBibtexEntry(bes); // ! look at ClipBoardManager Toolkit.getDefaultToolkit().getSystemClipboard().setContents(trbe, frame.getCurrentBasePanel()); frame.output(Localization.lang("Copied") + ' ' + (bes.size() > 1 ? bes.size() + " " + Localization.lang("entries") : "1 " + Localization.lang("entry") + '.')); } } }); diag.addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { contentPane.setDividerLocation(0.5f); } @Override public void windowClosing(WindowEvent event) { Globals.prefs.putInt(JabRefPreferences.SEARCH_DIALOG_WIDTH, diag.getSize().width); Globals.prefs.putInt(JabRefPreferences.SEARCH_DIALOG_HEIGHT, diag.getSize().height); } }); diag.getContentPane().add(contentPane, BorderLayout.CENTER); // Remember and default to last size: diag.setSize(new Dimension(Globals.prefs.getInt(JabRefPreferences.SEARCH_DIALOG_WIDTH), Globals.prefs.getInt(JabRefPreferences.SEARCH_DIALOG_HEIGHT))); diag.setLocationRelativeTo(frame); }
From source file:eu.cassandra.csn.gui.Stats.java
/** * // w w w.ja v a 2 s .c om * @param frame */ public static JPanel setNetworkStats(JFrame frame) { String[][] data = new String[][] { { "Virtual Days:", "" }, { "Number of nodes:", "" }, { "Number of edges:", "" }, { "Graph diameter:", "" }, { "Vertex Betweenness Centrality:", "" }, { "Edge Betweenness Centrality:", "" }, { "Total consumption:", "" }, { "Average consumption:", "" }, { "Peak consumption:", "" }, { "Unconnected vertices:", "" }, { "Clusters:", "" } }; String[] columnName = new String[] { "Metric", "Value" }; tableModel = new MyDefaultTableModel(data, columnName); JTable table = new JTable(tableModel); JScrollPane scrollPane = new JScrollPane(table); table.setFillsViewportHeight(true); String[][] dataSelected = new String[5][]; String[] columnNameSelected = new String[] { "Name", "Type", "Total Consumption", "Peak Comsumption", "Avg Consumption" }; tableModelSelected = new MyDefaultTableModel(dataSelected, columnNameSelected); JTable tableSelected = new JTable(tableModelSelected); JScrollPane scrollPaneSelected = new JScrollPane(tableSelected); tableSelected.setFillsViewportHeight(true); tableSelected.setPreferredSize(new Dimension(1600, 100)); scrollPaneSelected.setPreferredSize(new Dimension(1600, 100)); JPanel statsPanel = new JPanel(new BorderLayout()); statsPanel.add(scrollPane, BorderLayout.CENTER); chartPanel = Charts.createGraph("Power Consumption", "Hours", "Power (W)", new Double[0]); statsPanel.add(chartPanel, BorderLayout.PAGE_END); //frame.add(statsPanel,BorderLayout.EAST); frame.add(scrollPaneSelected, BorderLayout.PAGE_END); return statsPanel; }
From source file:gui.DownloadPanel.java
public DownloadPanel(JFrame parent, String databasePath, int connectionTimeout, int readTimeout) { this.parent = parent; setLayout(new BorderLayout()); this.connectionTimeout = connectionTimeout; this.readTimeout = readTimeout; downloadDialogs = new ArrayList<>(); String connectionUrl = "jdbc:sqlite:" + databasePath + File.separator + "cheetah.db"; databaseController = new DatabaseControllerImpl("org.sqlite.JDBC", connectionUrl, 0, "", ""); try {// ww w . j av a2s . c om databaseController.createTablesIfNotExist(); } catch (SQLException e) { e.printStackTrace(); } // Set up Downloads table. downloadsTableModel = new DownloadsTableModel(); downloadTable = new JTable(downloadsTableModel); popup = initPopupMenu(); downloadTable.getSelectionModel().addListSelectionListener(e -> { tableSelectionChanged(); if (downloadPanelListener != null) downloadPanelListener.downloadSelected(selectedDownload); }); // Allow only one row at a time to be selected. downloadTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // Set up ProgressBar as renderer for progress column. ProgressRenderer renderer = new ProgressRenderer(0, 100); renderer.setStringPainted(true); // show progress text downloadTable.setDefaultRenderer(JProgressBar.class, renderer); // Set table's row height large enough to fit JProgressBar. downloadTable.setRowHeight((int) renderer.getPreferredSize().getHeight()); downloadTable.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { super.mousePressed(e); int row = downloadTable.rowAtPoint(e.getPoint()); downloadTable.getSelectionModel().setSelectionInterval(row, row); DownloadDialog downloadDialog = getDownloadDialogByDownload(selectedDownload); if (e.getButton() == MouseEvent.BUTTON3) { // TODO right click popup.show(downloadTable, e.getX(), e.getY()); } else if (e.getClickCount() == 2) { // double click if (!downloadDialog.isVisible()) { downloadDialog.setVisible(true); } } } }); JScrollPane scrollPane = new JScrollPane(downloadTable); scrollPane.getViewport().setBackground(Color.WHITE); add(scrollPane, BorderLayout.CENTER); try { downloadList = databaseController.load(); } catch (Exception e) { e.printStackTrace(); } DownloadDialog downloadDialog; for (Download download : downloadList) { calculateDownloaded(download); download.setDownloadInfoListener(this); download.addDownloadStatusListener(this); downloadDialog = new DownloadDialog(parent, download); downloadDialog.setDownloadInfoListener(this); downloadDialogs.add(downloadDialog); downloadsTableModel.addDownload(download); downloadDialog.setDownloadRanges(download.getDownloadRangeList()); } setColumnWidths(); }
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 *//* w w w . ja va 2 s . co m*/ 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:com.diversityarrays.kdxplore.trials.SampleGroupViewer.java
private SampleGroupViewer(String title, KdxploreDatabase kdxdb, Trial trial, SampleGroup sampleGroup) { super(new BorderLayout()); this.title = title; // setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.kdxdb = kdxdb; this.trial = trial; this.sampleGroup = sampleGroup; initialise();// ww w . j a v a 2 s . c o m if (plotInfoByPlotId.isEmpty()) { add(new JLabel("No Plots available"), BorderLayout.CENTER); } else { tiChoiceTableModel = new TraitInstanceChoiceTableModel(); JTable tiTable = new JTable(tiChoiceTableModel); tiTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { List<Integer> modelRows = GuiUtil.getSelectedModelRows(tiTable); if (modelRows.isEmpty()) { Point pt = e.getPoint(); int vrow = tiTable.rowAtPoint(pt); if (vrow >= 0) { int mrow = tiTable.convertRowIndexToModel(vrow); if (mrow >= 0) { showPopupMenu(tiTable, pt, Arrays.asList(Integer.valueOf(mrow))); } } } else { showPopupMenu(tiTable, e.getPoint(), modelRows); } } } }); tableModel = new DataTableModel(plotInfoByPlotId); JTable table = new JTable(tableModel); DefaultTableCellRenderer r = new DefaultTableCellRenderer(); r.setHorizontalAlignment(SwingConstants.CENTER); table.setDefaultRenderer(String.class, r); splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(tiTable), new JScrollPane(table)); splitPane.setResizeWeight(0.2); add(splitPane, BorderLayout.CENTER); table.setTransferHandler(TableTransferHandler.initialiseForCopySelectAll(table, true)); } }
From source file:DOMTreeTest.java
public static JPanel elementPanel(Element e) { JPanel panel = new JPanel(); panel.add(new JLabel("Element: " + e.getTagName())); final NamedNodeMap map = e.getAttributes(); panel.add(new JTable(new AbstractTableModel() { public int getRowCount() { return map.getLength(); }/*from www. j av a 2 s . c om*/ public int getColumnCount() { return 2; } public Object getValueAt(int r, int c) { return c == 0 ? map.item(r).getNodeName() : map.item(r).getNodeValue(); } })); return panel; }
From source file:edu.ku.brc.specify.plugins.CollectionRelOneToManyPlugin.java
@Override public void initialize(Properties propertiesArg, boolean isViewModeArg) { super.initialize(propertiesArg, isViewModeArg); String relName = propertiesArg.getProperty("relname"); if (StringUtils.isNotEmpty(relName)) { DataProviderSessionIFace tmpSession = null; try {/*w w w.j a v a 2s . co m*/ tmpSession = DataProviderFactory.getInstance().createSession(); colRelType = tmpSession.getData(CollectionRelType.class, "name", relName, DataProviderSessionIFace.CompareType.Equals); if (colRelType != null) { leftSideCol = colRelType.getLeftSideCollection(); rightSideCol = colRelType.getRightSideCollection(); rightSideCol.getCollectionId(); leftSideCol.getCollectionId(); catNumFormatter = getCatNumFormatter(leftSideCol, rightSideCol); Collection currCollection = AppContextMgr.getInstance().getClassObject(Collection.class); isLeftSide = currCollection.getId().equals(leftSideCol.getId()); if (!isLeftSide) { // major error } } else { DBTableInfo ti = DBTableIdMgr.getInstance() .getInfoById(CollectionRelationship.getClassTableId()); UIRegistry.showError( String.format("The %s name '%s' doesn't exist (defined in the form for the plugin).", ti.getTitle(), relName)); } } catch (Exception ex) { ex.printStackTrace(); } finally { if (tmpSession != null) { tmpSession.close(); } } CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,2px,p", "f:p:g"), this); model = new ColObjDataModel(); table = new JTable(model); JScrollPane sp = UIHelper.createScrollPane(table, false); pb.add(sp, cc.xy(1, 1)); searchAddBtn = UIHelper.createIconBtn("SearchAdd", IconManager.IconSize.Std20, "", true, createSearchAL()); removeBtn = UIHelper.createIconBtn("Eraser", IconManager.IconSize.NonStd, "", true, createRemoveAL()); infoBtn = UIHelper.createIconBtn("InfoIcon", IconManager.IconSize.Std20, "", true, createInfoAL()); PanelBuilder rpb = new PanelBuilder(new FormLayout("f:p:g", "p,4px,p,4px,p, f:p:g")); int y = 1; rpb.add(infoBtn, cc.xy(1, y)); y += 2; if (!isViewMode) { rpb.add(searchAddBtn, cc.xy(1, y)); y += 2; rpb.add(removeBtn, cc.xy(1, y)); y += 2; } pb.add(rpb.getPanel(), cc.xy(3, 1)); UIHelper.makeTableHeadersCentered(table, true); UIHelper.setVisibleRowCount(table, 5); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setCellSelectionEnabled(false); table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(true); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { updateBtns(); } }); updateBtns(); } else { System.err.println(propertiesArg); log.error("CollectionRelOneToManyPlugin - initialize attribute for 'relname' is null and can't be!"); } }