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:logdruid.ui.mainpanel.EventRecordingSelectorPanel.java
/** * Create the panel.//from ww w.j a va 2 s . c o m */ public EventRecordingSelectorPanel(final Repository rep, Source src) { repository = rep; source = src; records = rep.getRecordings(EventRecording.class); // Collections.sort(records); Iterator it = records.iterator(); while (it.hasNext()) { Recording record = (Recording) it.next(); data.add(new Object[] { record.getName(), record.getRegexp(), record.getType(), src.isActiveRecordingOnSource(record) }); } model = new logdruid.ui.mainpanel.EventRecordingSelectorPanel.MyTableModel(data, header); logger.info("source is " + ((source == null) ? "null" : src.getSourceName())); 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); panel_1.add(scrollPane, BorderLayout.CENTER); table.setPreferredScrollableViewportSize(new Dimension(0, 150)); table.setFillsViewportHeight(true); table.setAutoCreateRowSorter(true); // Set up column sizes. initColumnSizes(table); setLayout(new BorderLayout(0, 0)); JSplitPane splitPane = new JSplitPane(); splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); add(splitPane); jPanelDetail = new JPanel(); splitPane.setBottomComponent(jPanelDetail); splitPane.setTopComponent(panel_1); 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 = 3; jPanelDetail.setLayout(new BorderLayout(0, 0)); 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.debug("ListSelectionListener - valueChanged"); jPanelDetail.removeAll(); recEditor = getEditor(repository.getRecording(EventRecording.class, selectedRow)); if (recEditor != null) { jPanelDetail.add(recEditor, BorderLayout.CENTER); } jPanelDetail.revalidate(); } } } }); if (repository.getRecordings(EventRecording.class).size() > 0) { recEditor = getEditor(repository.getRecording(EventRecording.class, 0)); jPanelDetail.add(recEditor, BorderLayout.CENTER); table.setRowSelectionInterval(0, 0); } if (model.getRowCount() > 0) { table.getRowSorter().toggleSortOrder(0); table.setRowSelectionInterval(0, 0); } }
From source file:edu.ku.brc.specify.plugins.sgr.SGRResultsDisplay.java
private JTable createTable(DefaultTableModel resultsTableModel, final List<List<Color>> rowColors) { JTable table = new JTable(resultsTableModel) { public Component prepareRenderer(TableCellRenderer renderer, int rowIndex, int colIndex) { Component c = super.prepareRenderer(renderer, rowIndex, colIndex); final Color bgColor = isCellSelected(rowIndex, colIndex) ? getSelectionBackground() : rowColors.get(rowIndex).get(colIndex); c.setBackground(bgColor);//from w w w. j a v a 2s.c o m return c; } }; DefaultTableCellRenderer tcr = getTableCellRenderer();//model.getRowInfoList()); for (int i = 0; i < resultsTableModel.getColumnCount(); i++) { if (resultsTableModel.getColumnClass(i) != Boolean.class) { table.setDefaultRenderer(resultsTableModel.getColumnClass(i), tcr); } } table.setCellSelectionEnabled(true); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); UIHelper.makeTableHeadersCentered(table, false); table.setDefaultRenderer(String.class, new BiColorTableCellRenderer(false)); table.setRowHeight(ROW_HEIGHT); autoResizeColWidth(table, resultsTableModel); return table; }
From source file:com.haskins.cloudtrailviewer.sidebar.EventsStats.java
private void addTable() { defaultTableModel.addColumn(""); defaultTableModel.addColumn("Property"); defaultTableModel.addColumn("Value"); final LegendColourRenderer cellRenderer = new LegendColourRenderer(); final JTable table = new JTable(defaultTableModel) { @Override// w w w . jav a 2s . co m public TableCellRenderer getCellRenderer(int row, int column) { if (column == 0) { return cellRenderer; } return super.getCellRenderer(row, column); } @Override public boolean isCellEditable(int row, int column) { return false; }; }; table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (e.getFirstIndex() >= 0) { String value = (String) defaultTableModel.getValueAt(table.getSelectedRow(), 1); eventTablePanel.setFilterString(value); } } }); TableColumn column; for (int i = 0; i < 3; i++) { column = table.getColumnModel().getColumn(i); switch (i) { case 0: column.setMinWidth(15); column.setMaxWidth(15); column.setPreferredWidth(15); break; case 2: column.setMinWidth(70); column.setMaxWidth(70); column.setPreferredWidth(70); break; } } JScrollPane tablecrollPane = new JScrollPane(table); tablecrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); this.add(tablecrollPane, BorderLayout.CENTER); }
From source file:edu.ku.brc.specify.config.init.TreeDefSetupPanel.java
/** * @param classType the class of the TreeDef * @param classTitle the already localized title of the actual tree * @param panelName the name of the panel * @param descKey L10N key to label description above the table * @param nextBtn the next button/* ww w .j a va2 s.co m*/ * @param dbPanel the */ public TreeDefSetupPanel(final Class<?> classType, final String classTitle, final String panelName, final String helpContext, final String descKey, final JButton nextBtn, final JButton prevBtn, final DisciplinePanel disciplinePanel) { super(panelName, helpContext, nextBtn, prevBtn); this.classType = classType; this.classTitle = classTitle; this.disciplinePanel = disciplinePanel; if (classType == TaxonTreeDef.class || classType == GeographyTreeDef.class || classType == StorageTreeDef.class) { model = new TreeDefTableModel(); if (classType != TaxonTreeDef.class) { loadTree(disciplinePanel != null && disciplinePanel.getDisciplineType() != null ? disciplinePanel.getDisciplineType().getDisciplineType() : null); } table = new JTable(model); directionCBX = UIHelper .createComboBox(new String[] { getResourceString("FORWARD"), getResourceString("REVERSE") }); fullnameDisplayTxt = new JEditorPane(); fullnameDisplayTxt.setBackground(Color.WHITE); fullnameDisplayTxt.setOpaque(true); fullnameDisplayTxt.setContentType("text/html"); fullnameDisplayTxt.setEditable(false); table.setRowSelectionAllowed(false); table.setColumnSelectionAllowed(false); //table.setDefaultRenderer(String.class, new BiColorTableCellRenderer(false)); model.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { updateBtnUI(); } }); JScrollPane spex = new JScrollPane(fullnameDisplayTxt, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder( new FormLayout("p,2px,p,250px,f:p:g", "p,4px,min(p;250px),4px,p,4px,65px,2px,p"), this); JScrollPane sp = createScrollPane(table); sp.getViewport().setBackground(Color.WHITE); String lbl = getLocalizedMessage(descKey, classTitle); pb.add(createLabel(lbl, SwingConstants.CENTER), cc.xyw(1, 1, 4)); pb.add(sp, cc.xyw(1, 3, 5)); pb.add(createI18NFormLabel("DIRECTION"), cc.xy(1, 5)); pb.add(directionCBX, cc.xy(3, 5)); pb.add(createI18NFormLabel("EXAMPLE"), cc.xy(1, 7)); pb.add(spex, cc.xywh(3, 7, 2, 3)); makeTableHeadersCentered(table, true); directionCBX.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateBtnUI(); } }); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { updateBtnUI(); int inx = table.getSelectedColumn(); if (inx > -1) { TreeDefRow row = treeDefList.get(table.getSelectedRow()); String msgKey = null; if (row.isRequired() && (inx == 1 || inx == 3)) { msgKey = inx == 1 ? "NO_CHANGE_INCL" : "NO_CHANGE_REQ"; } else if (inx == 4 && !row.isIncluded()) { msgKey = "NO_CHANGE_INFN"; } if (msgKey != null) { final String mk = msgKey; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { showLocalizedMsg(mk); } }); } } } } }); updateBtnUI(); } }
From source file:net.sf.webphotos.gui.util.FtpClient.java
/** * Construtor da classe. Prepara a interface de sincronizao. Configura o * sistema de sincronizao e confere o valor de enviarAltaResoluo para * enviar originais ou no. Seta os valores dos listeners de sincronizao * implementando os mtodos da interface Sync. *//*from www .j a v a2s .c o m*/ public FtpClient() { cp = getContentPane(); /** * Preparando a interface de sincronizao */ retry = 3; try { //TODO: transformar este acesso em parmetro do sistema ftp = (Sync) ApplicationContextResource.getBean("syncObject"); /** * Configurao do sistema de sincronizao */ ftp.setSyncFolder(ftpRoot); enviarAltaResolucao = ftp.isEnviarAltaResolucao(); ftp.loadSyncCache(); } catch (Exception ex) { Util.log("[FtpClient.run]/ERRO: Inexperado."); log.error(ex); System.exit(1); } // ajusta o valor de enviarAltaResolucao if (enviarAltaResolucao == false) { this.setTitle("Transmisso FTP - Sem Enviar Originais"); } else { this.setTitle("Transmisso FTP - Enviando Originais"); } txtLog.setFont(new Font("courier", Font.PLAIN, 11)); Util.setLoggingTextArea(txtLog); cp.setLayout(null); cp.add(lblArquivos); lblArquivos.setBounds(348, 3, 60, 18); cp.add(lblServidor); lblServidor.setBounds(8, 3, 340, 18); txtLog.setWrapStyleWord(true); txtLog.setLineWrap(true); cp.add(scrLog); scrLog.setBounds(8, 127, 400, 70); modeloTabela = new FTPTabelModel(ftp.getListaArquivos()); tabela = new JTable(modeloTabela); cp.add(tabela); scrTabela = new JScrollPane(tabela); cp.add(scrTabela); scrTabela.setBounds(8, 20, 400, 100); cp.validate(); // barraArquivoAtual, kbytes, botao cp.add(barraArquivoAtual); barraArquivoAtual.setStringPainted(true); barraArquivoAtual.setBounds(8, 235, 234, 18); barraArquivoAtual.setToolTipText("Progresso do arquivo atual"); cp.add(lblKbytesArquivoAtual); lblKbytesArquivoAtual.setBounds(246, 235, 58, 18); // barra, kbytes, botao cp.add(barra); barra.setStringPainted(true); barra.setBounds(8, 205, 234, 18); barra.setToolTipText("Progresso total"); cp.add(lblKbytes); lblKbytes.setBounds(246, 205, 58, 18); cp.add(btFechar); btFechar.setBounds(308, 204, 100, 20); btFechar.setEnabled(false); this.setSize(420, 300); this.setResizable(false); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(FtpClient.DO_NOTHING_ON_CLOSE); this.getContentPane().repaint(); this.setVisible(true); modal = new Modal(this); this.addWindowFocusListener(modal); // ouvinte para o boto fechar btFechar.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { exit(); } }); // ouvinte para o fechamento convencional do JFrame // TODO: trocar o if para checagem de parmetro if (1 == 2) { addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent evt) { exit(); } }); } ftp.setSyncListener(new SyncAdapter() { @Override public void connected(SyncEvent e) { lblServidor.setText(ftpHost + ":" + ftpPort + " / usurio: " + usuario); } @Override public void logonStarted(SyncEvent event) { // Autenticacao if (!event.isRetrying()) { if (BancoImagem.getBancoImagem().getUserFTP() != null) { // Vamos tentar conectar com a senha prpria de FTP usuario = BancoImagem.getBancoImagem().getUserFTP(); senha = BancoImagem.getBancoImagem().getPasswordFTP(); } else if (BancoImagem.getBancoImagem().getUser() != null) { // Ou o mesmo usurio/senha do banco de dados usuario = BancoImagem.getBancoImagem().getUser(); senha = BancoImagem.getBancoImagem().getPassword(); } else { showLogonDialog(); } } else { showLogonDialog(); } ftp.setUsuario(usuario); ftp.setSenha(senha); } @Override public void disconnected(SyncEvent e) { //TODO: repensar esse comando //Util.setLoggingTextArea(PainelWebFotos.getTxtLog()); btFechar.setEnabled(true); } private void showLogonDialog() { // Ou requisitamos do usurio Login l = new Login("FTP " + ftpHost); removeWindowFocusListener(modal); l.show(); addWindowFocusListener(modal); usuario = l.getUser(); senha = l.getPassword(); } }); ftp.setCopyStreamListener(new CopyStreamAdapter() { @Override public void bytesTransferred(long totalBytesTransferred, int bytesTransferred, long streamSize) { barraArquivoAtual.setValue((int) totalBytesTransferred); lblKbytesArquivoAtual.setText(Math.round((float) totalBytesTransferred / 1024) + " Kb"); } }); }
From source file:ExtendedDnDDemo.java
private JPanel createTable() { DefaultTableModel model = new DefaultTableModel(); model.addColumn("Column 0"); model.addColumn("Column 1"); model.addColumn("Column 2"); model.addColumn("Column 3"); model.addRow(new String[] { "Table 00", "Table 01", "Table 02", "Table 03" }); model.addRow(new String[] { "Table 10", "Table 11", "Table 12", "Table 13" }); model.addRow(new String[] { "Table 20", "Table 21", "Table 22", "Table 23" }); model.addRow(new String[] { "Table 30", "Table 31", "Table 32", "Table 33" }); JTable table = new JTable(model); table.getTableHeader().setReorderingAllowed(false); table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); JScrollPane scrollPane = new JScrollPane(table); scrollPane.setPreferredSize(new Dimension(400, 100)); table.setDragEnabled(true);//from w w w . j av a 2 s . c o m table.setTransferHandler(new TableTransferHandler()); JPanel panel = new JPanel(new BorderLayout()); panel.add(scrollPane, BorderLayout.CENTER); panel.setBorder(BorderFactory.createTitledBorder("Table")); return panel; }
From source file:edu.ku.brc.specify.dbsupport.cleanuptools.GeographyMerging.java
/** * /* ww w.ja v a 2 s . co m*/ */ public boolean start() { DataProviderSessionIFace session = null; try { session = DataProviderFactory.getInstance().createSession(); GeographyTreeDef gtd = AppContextMgr.getInstance().getClassObject(Discipline.class) .getGeographyTreeDef(); geoTreeDef = session.get(GeographyTreeDef.class, gtd.getId()); geoTreeDef.forceLoad(); } catch (Exception ex) { return false; } finally { if (session != null) session.close(); } headers[0] = getResourceString("CLNUP_PRIMARY"); headers[1] = getResourceString("CLNUP_INCLUDE"); for (int i = 0; i < 4; i++) { String sql = "SELECT Name FROM geographytreedefitem WHERE GeographyTreeDefID = GEOTREEDEFID AND RankID = " + (i * 100); sql = QueryAdjusterForDomain.getInstance().adjustSQL(sql); levelNames[3 - i] = BasicSQLUtils.querySingleObj(sql); } String sql = "SELECT g1.Name, g2.Name, g3.Name, g1.GeographyID FROM geography g1 LEFT OUTER JOIN geography g2 ON g1.ParentID = g2.GeographyID " + "INNER JOIN geography g3 ON g2.ParentID = g3.GeographyID WHERE g1.Name = ? AND g1.RankID = ?"; try { pStmt = DBConnection.getInstance().getConnection().prepareStatement(sql); } catch (SQLException e) { e.printStackTrace(); } if (!findDuplicates()) { return false; } model = new GeoItemsModel(); table = new JTable(model); UIHelper.makeTableHeadersCentered(table, true); JScrollPane sp = UIHelper.createScrollPane(table, true); CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "f:p:g")); pb.add(sp, cc.xy(1, 1)); pb.setDefaultDialogBorder(); dlg = new CustomDialog((Frame) UIRegistry.getTopWindow(), " ", true, CustomDialog.OKCANCELAPPLYHELP, pb.getPanel()) // Title is set later { @Override protected void cancelButtonPressed() // Skip Button { doNextGeographyInList(); } @Override protected void applyButtonPressed() // Accept Button { doAccept(); } }; dlg.setCancelLabel(getResourceString("GeoLocateResultsChooser.SKIP")); //$NON-NLS-1$ dlg.setApplyLabel(getResourceString("GeoLocateResultsChooser.ACCEPT")); //$NON-NLS-1$ dlg.setOkLabel(getResourceString("GeoLocateResultsChooser.QUIT")); //$NON-NLS-1$ dlg.createUI(); // Start the process. currIndex = -1; doNextGeographyInList(); dlg.pack(); UIHelper.centerAndShow(dlg, 800, dlg.getSize().height); return true; }
From source file:instance.gui.InstanceGUI.java
private void createSnapshotTable() { snapshotModel = new DefaultTableModel(new String[][] {}, snapshotTableColumns); snapshotTable = new JTable(snapshotModel) { private static final long serialVersionUID = 6454534842446167244L; public boolean isCellEditable(int rowIndex, int colIndex) { return false; }/*from www.ja v a 2 s. co m*/ }; snapshotTable.addMouseListener(snapshotPopupListener); snapshotTable.getColumnModel().getColumn(0).setPreferredWidth(20); JScrollPane pane = new JScrollPane(snapshotTable); snapshotSection.add(pane); }
From source file:edu.ku.brc.af.ui.weblink.WebLinkEditorDlg.java
/** * @param webLinkDef the WebLink to be edited * @throws HeadlessException//www . j a v a2s . co m */ public WebLinkEditorDlg(final WebLinkDef webLinkDef, final DBTableInfo tableInfo) throws HeadlessException { super((Frame) UIRegistry.getTopWindow(), getResourceString("WebLinkArgDlg.WEB_LNK_EDTR"), true, //$NON-NLS-1$ OKCANCELHELP, null); this.webLinkDef = webLinkDef; this.tableInfo = tableInfo; availFieldNames = new Vector<String>(); if (tableInfo != null) { for (DBFieldInfo fi : tableInfo.getFields()) { if (fi.getType().equals("java.lang.String")) { fieldInfoHash.put(fi.getName(), fi); availFieldNames.add(fi.getName()); } } List<String> treeFieldNames = DBTableIdMgr.getInstance().getTreeFieldNames(tableInfo); if (treeFieldNames != null) { for (String fName : treeFieldNames) { availFieldNames.add(fName); } } avModel = new AvailFieldsTableModel(); Collections.sort(availFieldNames); availableFields = new JTable(avModel); } for (WebLinkDefArg arg : webLinkDef.getArgs()) { try { WebLinkDefArg wlda = (WebLinkDefArg) arg.clone(); String fName = wlda.getName(); if (tableInfo != null) { boolean isField = fieldInfoHash.get(fName) != null; wlda.setField(isField); wlda.setPrompt(!isField); } if (wlda.getTitle() != null) { titleHash.put(fName, wlda.getTitle()); } args.add(wlda); } catch (CloneNotSupportedException ex) { } } helpContext = "WEBLNK_ARGS_EDITOR"; }
From source file:SampleTableModel.java
@Override public void init() { tableModel = new SampleTableModel(); // create javafx panel for charts chartFxPanel = new JFXPanel(); chartFxPanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, PANEL_HEIGHT_INT)); //JTable/*from ww w . ja va 2 s . co m*/ JTable table = new JTable(tableModel); table.setAutoCreateRowSorter(true); table.setGridColor(Color.DARK_GRAY); SwingInterop.DecimalFormatRenderer renderer = new SwingInterop.DecimalFormatRenderer(); renderer.setHorizontalAlignment(JLabel.RIGHT); for (int i = 0; i < table.getColumnCount(); i++) { table.getColumnModel().getColumn(i).setCellRenderer(renderer); } JScrollPane tablePanel = new JScrollPane(table); tablePanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, TABLE_PANEL_HEIGHT_INT)); JPanel chartTablePanel = new JPanel(); chartTablePanel.setLayout(new BorderLayout()); //Split pane that holds both chart and table JSplitPane jsplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); jsplitPane.setTopComponent(chartTablePanel); jsplitPane.setBottomComponent(tablePanel); jsplitPane.setDividerLocation(410); chartTablePanel.add(chartFxPanel, BorderLayout.CENTER); // add(tablePanel, BorderLayout.CENTER); add(jsplitPane, BorderLayout.CENTER); // create JavaFX scene Platform.runLater(new Runnable() { @Override public void run() { createScene(); } }); }