List of usage examples for javax.swing JTable AUTO_RESIZE_OFF
int AUTO_RESIZE_OFF
To view the source code for javax.swing JTable AUTO_RESIZE_OFF.
Click Source Link
From source file:DatabaseBrowser.java
public DatabaseBrowser() throws Exception { ConnectionDialog cd = new ConnectionDialog(this); connection = cd.getConnection();//from w w w .ja v a2 s . com Container pane = getContentPane(); pane.add(getSelectionPanel(), BorderLayout.NORTH); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); refreshTable(); pane.add(new JScrollPane(table), BorderLayout.CENTER); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(600, 450); setVisible(true); }
From source file:core.reporting.ImportFromFile.java
public ImportFromFile(Record rmod, String coldeff) { super("title_imporFromfile"); this.recordModel = rmod; this.columnModelDef = coldeff; this.tempBuffer = new Vector<Record>(); this.saveAction = new SaveAction(this); saveAction.setEnabled(false);/*www.j av a 2 s .co m*/ this.refreshAction = new TAbstractAction(TAbstractAction.TABLE_SCOPE) { @Override public void actionPerformed(ActionEvent arg0) { validateCSVFile(); } }; refreshAction.setIcon("RefreshAction"); refreshAction.setToolTip("ttaction.RefreshAction"); setToolBar(false, new NativeFileChooser(NativeFileChooser.OPEN_STYLE, this), refreshAction, saveAction); putClientProperty(TConstants.JTABLE_AUTO_RESIZE_MODE, JTable.AUTO_RESIZE_OFF); addPropertyChangeListener(this); String fldl = "<ol>"; File f = TResourceUtils.getFile(columnModelDef + ".csv"); try { BufferedReader br = new BufferedReader(new FileReader(f)); String lin = br.readLine(); while ((lin = br.readLine()) != null) { fldl += "<li>" + lin.split("[,]")[0]; } fldl += "</ol>"; setMessage("inputfile.msg01", fldl); setView(TABLE_VIEW); setVisibleToolBar(true); } catch (Exception e) { setMessage("inputfile.msg06", f); SystemLog.logException(e); } }
From source file:com.sshtools.common.ui.PreferencesStore.java
/** * * * @param table//from w ww . j a va 2 s . c om * @param pref * @param defaultWidths * * @throws IllegalArgumentException */ public static void restoreTableMetrics(JTable table, String pref, int[] defaultWidths) { // Check the table columns may be resized correctly if (table.getAutoResizeMode() != JTable.AUTO_RESIZE_OFF) { throw new IllegalArgumentException("Table AutoResizeMode must be JTable.AUTO_RESIZE_OFF"); } // Restore the table column widths and positions for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) { try { table.moveColumn(table.convertColumnIndexToView(getInt(pref + ".column." + i + ".position", i)), i); table.getColumnModel().getColumn(i) .setPreferredWidth(getInt(pref + ".column." + i + ".width", (defaultWidths == null) ? table.getColumnModel().getColumn(i).getPreferredWidth() : defaultWidths[i])); } catch (NumberFormatException nfe) { } } }
From source file:MainClass.java
public MainClass() { super("Row Header Test"); setSize(300, 200);/*from w w w. j a v a 2s .co m*/ setDefaultCloseOperation(EXIT_ON_CLOSE); TableModel tm = new AbstractTableModel() { String data[] = { "", "a", "b", "c", "d", "e" }; String headers[] = { "Row #", "Column 1", "Column 2", "Column 3", "Column 4", "Column 5" }; public int getColumnCount() { return data.length; } public int getRowCount() { return 1000; } public String getColumnName(int col) { return headers[col]; } public Object getValueAt(int row, int col) { return data[col] + row; } }; TableColumnModel cm = new DefaultTableColumnModel() { boolean first = true; public void addColumn(TableColumn tc) { if (first) { first = false; return; } tc.setMinWidth(150); super.addColumn(tc); } }; TableColumnModel rowHeaderModel = new DefaultTableColumnModel() { boolean first = true; public void addColumn(TableColumn tc) { if (first) { tc.setMaxWidth(tc.getPreferredWidth()); super.addColumn(tc); first = false; } } }; JTable jt = new JTable(tm, cm); JTable headerColumn = new JTable(tm, rowHeaderModel); jt.createDefaultColumnsFromModel(); headerColumn.createDefaultColumnsFromModel(); jt.setSelectionModel(headerColumn.getSelectionModel()); headerColumn.setBackground(Color.lightGray); headerColumn.setColumnSelectionAllowed(false); headerColumn.setCellSelectionEnabled(false); JViewport jv = new JViewport(); jv.setView(headerColumn); jv.setPreferredSize(headerColumn.getMaximumSize()); jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); JScrollPane jsp = new JScrollPane(jt); jsp.setRowHeader(jv); jsp.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, headerColumn.getTableHeader()); getContentPane().add(jsp, BorderLayout.CENTER); }
From source file:com.clough.android.adbv.view.UpdateTableDialog.java
public UpdateTableDialog(java.awt.Frame parent, boolean modal, String outputResult, String tableName, Object[] columnNames) {//from w ww. j a v a 2s . c o m super(parent, modal); initComponents(); this.outputResult = outputResult; this.tableName = tableName; this.columnNames = columnNames; this.mainFrame = (MainFrame) parent; setTitle("Update table `" + tableName + "`"); setLocationRelativeTo(null); resultTable.setModel(new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { return false; } }); resultTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); defaultTableModel = (DefaultTableModel) resultTable.getModel(); for (Object columnName : columnNames) { defaultTableModel.addColumn(columnName); } tableColumnAdjuster = new TableColumnAdjuster(resultTable); processResult(); }
From source file:com.github.alexfalappa.nbspringboot.navigator.RequestMappingNavigatorPanel.java
/** * public no arg constructor needed for system to instantiate provider well */// w w w . ja va 2 s .c om public RequestMappingNavigatorPanel() { table = new ETable(); mappedElementsModel = new MappedElementsModel(); mappedElementGatheringTaskFactory = new ElementScanningTaskFactory(table, mappedElementsModel); table.setModel(mappedElementsModel); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setColumnSorted(0, true, 1); table.setDefaultRenderer(RequestMethod.class, new RequestMethodCellRenderer()); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent event) { final int selectedRow = ((ListSelectionModel) event.getSource()).getMinSelectionIndex(); if (event.getValueIsAdjusting() || selectedRow < 0) { return; } final MappedElement mappedElement = mappedElementsModel .getElementAt(table.convertRowIndexToModel(selectedRow)); ElementOpen.open(mappedElement.getFileObject(), mappedElement.getHandle()); try { final DataObject dataObject = DataObject.find(mappedElement.getFileObject()); final EditorCookie editorCookie = dataObject.getLookup().lookup(EditorCookie.class); if (editorCookie != null) { editorCookie.openDocument(); JEditorPane[] p = editorCookie.getOpenedPanes(); if (p.length > 0) { p[0].requestFocus(); } } } catch (IOException e) { } } }); final JPanel panel = new JPanel(new BorderLayout()); panel.add(new JScrollPane(table), BorderLayout.CENTER); this.component = panel; this.contextListener = new LookupListener() { @Override public void resultChanged(LookupEvent le) { } }; }
From source file:org.drugis.mtc.gui.results.ResultsComponentFactory.java
private static JTable createTableWithoutHeaders(NetworkRelativeEffectTableModel dm) { final JTable table = new JTable(dm); table.setTableHeader(null);/*from w ww .ja v a2 s. c o m*/ table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); for (final TableColumn c : Collections.list(table.getColumnModel().getColumns())) { c.setMinWidth(170); c.setPreferredWidth(170); } TableCopyHandler.registerCopyAction(table); return table; }
From source file:lu.lippmann.cdb.ext.hydviga.ui.GapsOverviewPanel.java
public void refresh(final Instances dataSet, final int dateIdx) { final Instances gapsDescriptionsDataset = GapsUtil.buildGapsDescription(gcp, dataSet, dateIdx); final JXTable gapsDescriptionsTable = new JXTable(); final InstanceTableModel gapsDescriptionsTableModel = new InstanceTableModel(false); gapsDescriptionsTableModel.setDataset(gapsDescriptionsDataset); gapsDescriptionsTable.setModel(gapsDescriptionsTableModel); gapsDescriptionsTable.setEditable(true); gapsDescriptionsTable.setShowHorizontalLines(false); gapsDescriptionsTable.setShowVerticalLines(false); gapsDescriptionsTable.setVisibleRowCount(5); gapsDescriptionsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); gapsDescriptionsTable.setSortable(false); gapsDescriptionsTable.packAll();// ww w . j a v a 2 s. co m gapsDescriptionsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); gapsDescriptionsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { int modelRow = gapsDescriptionsTable.getSelectedRow(); if (modelRow < 0) modelRow = 0; final String attrname = gapsDescriptionsTableModel.getValueAt(modelRow, 1).toString(); final Attribute attr = dataSet.attribute(attrname); final int gapsize = (int) Double .valueOf(gapsDescriptionsTableModel.getValueAt(modelRow, 5).toString()).doubleValue(); final int position = (int) Double .valueOf(gapsDescriptionsTableModel.getValueAt(modelRow, 6).toString()).doubleValue(); try { final ChartPanel cp = GapsUIUtil.buildGapChartPanel(dataSet, dateIdx, attr, gapsize, position); visualOverviewPanel.removeAll(); visualOverviewPanel.add(cp, BorderLayout.CENTER); geomapPanel.removeAll(); geomapPanel.add(gcp.getMapPanel(Arrays.asList(attrname), new ArrayList<String>(), false)); jxp.updateUI(); } catch (Exception ee) { ee.printStackTrace(); } } } }); gapsDescriptionsTable.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(final MouseEvent e) { final InstanceTableModel instanceTableModel = (InstanceTableModel) gapsDescriptionsTable.getModel(); final int row = gapsDescriptionsTable.rowAtPoint(e.getPoint()); //final int row=gapsDescriptionsTable.getSelectedRow(); final int modelRow = gapsDescriptionsTable.convertRowIndexToModel(row); //final int modelRow=(int)Double.valueOf(instanceTableModel.getValueAt(row,0).toString()).doubleValue(); //System.out.println(row+" "+modelRow); final String attrname = instanceTableModel.getValueAt(modelRow, 1).toString(); final Attribute attr = dataSet.attribute(attrname); final int gapsize = (int) Double.valueOf(instanceTableModel.getValueAt(modelRow, 5).toString()) .doubleValue(); final int position = (int) Double.valueOf(instanceTableModel.getValueAt(modelRow, 6).toString()) .doubleValue(); if (!e.isPopupTrigger()) { // nothing? } else { final JPopupMenu jPopupMenu = new JPopupMenu("feur"); final JMenuItem interactiveFillMenuItem = new JMenuItem("Fill this gap (interactively)"); interactiveFillMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final GapFillingFrame jxf = new GapFillingFrame(atv, dataSet, attr, dateIdx, GapsUtil.getCountOfValuesBeforeAndAfter(gapsize), position, gapsize, gcp, false); jxf.setSize(new Dimension(900, 700)); //jxf.setExtendedState(Frame.MAXIMIZED_BOTH); jxf.setLocationRelativeTo(jPopupMenu); jxf.setVisible(true); //jxf.setResizable(false); } }); jPopupMenu.add(interactiveFillMenuItem); final JMenuItem lookupInKnowledgeDBMenuItem = new JMenuItem( "Show the most similar cases from KnowledgeDB"); lookupInKnowledgeDBMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final double x = gcp.getCoordinates(attrname)[0]; final double y = gcp.getCoordinates(attrname)[1]; final String season = instanceTableModel.getValueAt(modelRow, 3).toString() .split("/")[0]; final boolean isDuringRising = instanceTableModel.getValueAt(modelRow, 11).toString() .equals("true"); try { final Calendar cal = Calendar.getInstance(); final String dateAsString = instanceTableModel.getValueAt(modelRow, 2).toString() .replaceAll("'", ""); cal.setTime(FormatterUtil.DATE_FORMAT.parse(dateAsString)); final int year = cal.get(Calendar.YEAR); new SimilarCasesFrame(dataSet, dateIdx, gcp, attrname, gapsize, position, x, y, year, season, isDuringRising); } catch (Exception e1) { e1.printStackTrace(); } } }); jPopupMenu.add(lookupInKnowledgeDBMenuItem); final JMenuItem mExport = new JMenuItem("Export this table as CSV"); mExport.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final JFileChooser fc = new JFileChooser(); fc.setAcceptAllFileFilterUsed(false); final int returnVal = fc.showSaveDialog(gapsDescriptionsTable); if (returnVal == JFileChooser.APPROVE_OPTION) { try { final File file = fc.getSelectedFile(); WekaDataAccessUtil.saveInstancesIntoCSVFile(gapsDescriptionsDataset, file); } catch (Exception ee) { ee.printStackTrace(); } } } }); jPopupMenu.add(mExport); jPopupMenu.show(gapsDescriptionsTable, e.getX(), e.getY()); } } }); final int tableWidth = (int) gapsDescriptionsTable.getPreferredSize().getWidth() + 30; final JScrollPane scrollPane = new JScrollPane(gapsDescriptionsTable); scrollPane.setPreferredSize(new Dimension(Math.min(tableWidth, 500), 500)); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); this.tablePanel.removeAll(); this.tablePanel.add(scrollPane, BorderLayout.CENTER); this.visualOverviewPanel.removeAll(); /* automatically compute the most similar series and the 'rising' flag */ new AbstractSimpleAsync<Void>(false) { @Override public Void execute() throws Exception { final int rc = gapsDescriptionsTableModel.getRowCount(); for (int i = 0; i < rc; i++) { final int modelRow = i; try { final String attrname = gapsDescriptionsTableModel.getValueAt(modelRow, 1).toString(); final Attribute attr = dataSet.attribute(attrname); final int gapsize = (int) Double .valueOf(gapsDescriptionsTableModel.getValueAt(modelRow, 5).toString()) .doubleValue(); final int position = (int) Double .valueOf(gapsDescriptionsTableModel.getValueAt(modelRow, 6).toString()) .doubleValue(); /* most similar */ gapsDescriptionsTableModel.setValueAt("...", modelRow, 7); final int cvba = GapsUtil.getCountOfValuesBeforeAndAfter(gapsize); Instances gapds = WekaDataProcessingUtil.buildFilteredDataSet(dataSet, 0, dataSet.numAttributes() - 1, Math.max(0, position - cvba), Math.min(position + gapsize + cvba, dataSet.numInstances() - 1)); final String mostsimilar = WekaTimeSeriesSimilarityUtil.findMostSimilarTimeSerie(gapds, attr, WekaTimeSeriesUtil.getNamesOfAttributesWithoutGap(gapds), false); gapsDescriptionsTableModel.setValueAt(mostsimilar, modelRow, 7); /* 'rising' flag */ gapsDescriptionsTableModel.setValueAt("...", modelRow, 11); final List<String> attributeNames = WekaDataStatsUtil.getAttributeNames(dataSet); attributeNames.remove("timestamp"); final String nearestStationName = gcp.findNearestStation(attr.name(), attributeNames); final Attribute nearestStationAttr = dataSet.attribute(nearestStationName); //System.out.println(nearestStationName+" "+nearestStationAttr); final boolean isDuringRising = GapsUtil.isDuringRising(dataSet, position, gapsize, new int[] { dateIdx, attr.index(), nearestStationAttr.index() }); gapsDescriptionsTableModel.setValueAt(isDuringRising, modelRow, 11); gapsDescriptionsTableModel.fireTableDataChanged(); } catch (Exception e) { gapsDescriptionsTableModel.setValueAt("n/a", modelRow, 7); gapsDescriptionsTableModel.setValueAt("n/a", modelRow, 11); e.printStackTrace(); } } return null; } @Override public void onSuccess(Void result) { } @Override public void onFailure(Throwable caught) { caught.printStackTrace(); } }.start(); /* select the first row */ gapsDescriptionsTable.setRowSelectionInterval(0, 0); }
From source file:GeMSE.GS.Analysis.Stats.OneSamplePearsonsCorrelationPanel.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 w w .ja v a2 s . c o m*/ */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jTabbedPane1 = new javax.swing.JTabbedPane(); jPanel1 = new javax.swing.JPanel(); HeatmapL = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); matrixDG = new javax.swing.JTable(); HeatmapL.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); HeatmapL.setText("GeMSE"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout .setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap() .addComponent(HeatmapL, javax.swing.GroupLayout.DEFAULT_SIZE, 607, Short.MAX_VALUE) .addContainerGap())); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap() .addComponent(HeatmapL, javax.swing.GroupLayout.DEFAULT_SIZE, 473, Short.MAX_VALUE) .addContainerGap())); jTabbedPane1.addTab(" Heat Map ", jPanel1); matrixDG.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { {}, {}, {}, {} }, new String[] { })); matrixDG.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF); matrixDG.setCellSelectionEnabled(true); matrixDG.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION); jScrollPane1.setViewportView(matrixDG); jTabbedPane1.addTab(" Grid View ", jScrollPane1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( layout.createSequentialGroup().addContainerGap().addComponent(jTabbedPane1).addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap() .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 531, Short.MAX_VALUE) .addContainerGap())); }
From source file:RowHeaderTable.java
public RowHeaderTable() { super("Row Header Test"); setSize(300, 200);/*from w w w . j a v a 2 s . c o m*/ setDefaultCloseOperation(EXIT_ON_CLOSE); TableModel tm = new AbstractTableModel() { String data[] = { "", "a", "b", "c", "d", "e" }; String headers[] = { "Row #", "Column 1", "Column 2", "Column 3", "Column 4", "Column 5" }; public int getColumnCount() { return data.length; } public int getRowCount() { return 1000; } public String getColumnName(int col) { return headers[col]; } // Synthesize some entries using the data values & the row # public Object getValueAt(int row, int col) { return data[col] + row; } }; // Create a column model for the main table. This model ignores the // first // column added, and sets a minimum width of 150 pixels for all others. TableColumnModel cm = new DefaultTableColumnModel() { boolean first = true; public void addColumn(TableColumn tc) { // Drop the first column . . . that'll be the row header if (first) { first = false; return; } tc.setMinWidth(150); // just for looks, really... super.addColumn(tc); } }; // Create a column model that will serve as our row header table. This // model picks a maximum width and only stores the first column. TableColumnModel rowHeaderModel = new DefaultTableColumnModel() { boolean first = true; public void addColumn(TableColumn tc) { if (first) { tc.setMaxWidth(tc.getPreferredWidth()); super.addColumn(tc); first = false; } // Drop the rest of the columns . . . this is the header column // only } }; JTable jt = new JTable(tm, cm); // Set up the header column and get it hooked up to everything JTable headerColumn = new JTable(tm, rowHeaderModel); jt.createDefaultColumnsFromModel(); headerColumn.createDefaultColumnsFromModel(); // Make sure that selections between the main table and the header stay // in sync (by sharing the same model) jt.setSelectionModel(headerColumn.getSelectionModel()); // Make the header column look pretty //headerColumn.setBorder(BorderFactory.createEtchedBorder()); headerColumn.setBackground(Color.lightGray); headerColumn.setColumnSelectionAllowed(false); headerColumn.setCellSelectionEnabled(false); // Put it in a viewport that we can control a bit JViewport jv = new JViewport(); jv.setView(headerColumn); jv.setPreferredSize(headerColumn.getMaximumSize()); // With out shutting off autoResizeMode, our tables won't scroll // correctly (horizontally, anyway) jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // We have to manually attach the row headers, but after that, the // scroll // pane keeps them in sync JScrollPane jsp = new JScrollPane(jt); jsp.setRowHeader(jv); jsp.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, headerColumn.getTableHeader()); getContentPane().add(jsp, BorderLayout.CENTER); }