List of usage examples for javax.swing.table DefaultTableCellRenderer setHorizontalAlignment
@BeanProperty(visualUpdate = true, enumerationValues = { "SwingConstants.LEFT", "SwingConstants.CENTER", "SwingConstants.RIGHT", "SwingConstants.LEADING", "SwingConstants.TRAILING" }, description = "The alignment of the label's content along the X axis.") public void setHorizontalAlignment(int alignment)
From source file:net.sf.jabref.gui.maintable.MainTable.java
@Override public TableCellRenderer getCellRenderer(int row, int column) { int score = -3; DefaultTableCellRenderer renderer = MainTable.defRenderer; CellRendererMode status = getCellStatus(row, column); if ((model.getSearchState() != MainTableDataModel.DisplayOption.FLOAT) || matches(row, model.getSearchState() != MainTableDataModel.DisplayOption.DISABLED ? SearchMatcher.INSTANCE : null)) {//from w w w. j av a 2s. c om score++; } if ((model.getGroupingState() != MainTableDataModel.DisplayOption.FLOAT) || matches(row, model.getGroupingState() != MainTableDataModel.DisplayOption.DISABLED ? GroupMatcher.INSTANCE : null)) { score += 2; } // Now, a grayed out renderer is for entries with -1, and // a very grayed out one for entries with -2 if (score < -1) { if (column == 0) { MainTable.veryGrayedOutNumberRenderer.setNumber(row); renderer = MainTable.veryGrayedOutNumberRenderer; } else { renderer = MainTable.veryGrayedOutRenderer; } } else if (score == -1) { if (column == 0) { MainTable.grayedOutNumberRenderer.setNumber(row); renderer = MainTable.grayedOutNumberRenderer; } else { renderer = MainTable.grayedOutRenderer; } } else if (column == 0) { if (isComplete(row)) { MainTable.compRenderer.setNumber(row); int marking = isMarked(row); if (marking > 0) { marking = Math.min(marking, EntryMarker.MARK_COLOR_LEVELS); renderer = MainTable.markedNumberRenderers.get(marking - 1); MainTable.markedNumberRenderers.get(marking - 1).setNumber(row); } else { renderer = MainTable.compRenderer; } } else { // Return a renderer with red background if the entry is incomplete. MainTable.incRenderer.setNumber(row); renderer = MainTable.incRenderer; } renderer.setHorizontalAlignment(JLabel.CENTER); } else if (tableColorCodes) { if (status == CellRendererMode.REQUIRED) { renderer = MainTable.reqRenderer; } else if (status == CellRendererMode.OPTIONAL) { renderer = MainTable.optRenderer; } } // For MARKED feature: int marking = isMarked(row); if ((column != 0) && (marking > 0)) { marking = Math.min(marking, EntryMarker.MARK_COLOR_LEVELS); renderer = MainTable.markedRenderers.get(marking - 1); } return renderer; }
From source file:de.main.sessioncreator.DesktopApplication1View.java
private void showReportPanel() { sessionWizardMenuItem.setEnabled(true); reviewVieMenuItem.setEnabled(true);//from w ww.j a v a 2 s. c om sessionReportMenuItem.setEnabled(false); viewReviewsPanel.setVisible(false); mainPanel.validate(); wizardPanel.setVisible(false); mainPanel.validate(); reportOverviewTable.setVisible(false); reportPanel.setVisible(true); mainPanel.validate(); this.getFrame().setTitle("SessionCreator - Report"); //Backgroundprozess to fill data to the reportPanel class ReportData extends SwingWorker<DefaultTableModel, Void> { @Override protected DefaultTableModel doInBackground() throws Exception { rh.addReport(reportChartPanel); reportScrollPOverviewTabel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); reportScrollPOverviewTabel.setToolTipText("Please wait..."); reportlblSum.setText("Sums of Charters done: <counting>"); progressBar.setIndeterminate(true); progressBar.setVisible(true); model = new DefaultTableModel(); reportOverviewTable.removeAll(); model = rh.getTableModel(); reportOverviewTable.setModel(model); reportOverviewTable.setVisible(true); String count = rh.getAllSessionCount(model); reportlblSum.setText("Sums of Charters done: " + count); String[] text = rh.getAllBugsAndIssues(); reportlblBug.setText(text[0]); reportlblIssue.setText(text[1]); return model; } @Override protected void done() { try { reportScrollPOverviewTabel.setCursor(Cursor.getDefaultCursor()); reportScrollPOverviewTabel.setToolTipText(""); progressBar.setIndeterminate(false); progressBar.setVisible(false); reportScrollPOverviewTabel.setEnabled(true); reportOverviewTable.setFillsViewportHeight(true); reportOverviewTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); TableRowSorter<DefaultTableModel> rowSorter = new TableRowSorter<DefaultTableModel>(model); reportOverviewTable.setRowSorter(rowSorter); rowSorter.setComparator(1, new Comparator<Integer>() { @Override public int compare(Integer int1, Integer int2) { return int1.intValue() - int2.intValue(); } }); TableColumn column = null; for (int i = 0; i < 2; i++) { column = reportOverviewTable.getColumnModel().getColumn(i); if (i == 1) { column.setPreferredWidth(10); //third column is bigger DefaultTableCellRenderer myRenderer = new DefaultTableCellRenderer(); //Textalignment in second column right myRenderer.setHorizontalAlignment(SwingConstants.RIGHT); column.setCellRenderer(myRenderer); } else { column.setPreferredWidth(490); } } } catch ( /* InterruptedException, ExecutionException */Exception e) { } } } new ReportData().execute(); }
From source file:com.pianobakery.complsa.MainGui.java
private void createUIComponents() { this.indexTypeComboBox = new JComboBox(indexType); this.termComboBox = new JComboBox(termweights); //docSearchTitles = new String[]{"%Similarity","Path","Show"}; docSearchResModel = new DocSearchModel(); docSearchResTable = new JTable(docSearchResModel); docSearchResTable.setShowHorizontalLines(false); docSearchResTable.setShowVerticalLines(true); docSearchResTable.setFillsViewportHeight(true); docSearchResTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); docSearchResTable.setShowGrid(false); docSearchResTable.setGridColor(Color.DARK_GRAY); docSearchResTable.setAutoscrolls(true); docSearchResTable.getColumn("%Similarities:").setPreferredWidth(100); docSearchResTable.getColumn("%Similarities:").setWidth(25); docSearchResTable.getColumn("Filename:").setPreferredWidth(600); docSearchResTable.getColumn("Filename:").setWidth(100); docSearchResTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); DefaultTableCellRenderer leftRenderer = new DefaultTableCellRenderer(); leftRenderer.setHorizontalAlignment(JLabel.LEFT); docSearchResTable.getColumnModel().getColumn(0).setCellRenderer(leftRenderer); termSearchTitles = new String[] { "%Similarities:", "Terms:" }; termSearchResModel = new DefaultTableModel(termSearchTitles, 0) { @Override/* ww w.j a v a 2 s .com*/ public boolean isCellEditable(int row, int column) { return false; } }; termSearchResTable = new JTable(termSearchResModel); termSearchResTable.setShowVerticalLines(true); termSearchResTable.setShowHorizontalLines(false); termSearchResTable.setFillsViewportHeight(true); termSearchResTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); termSearchResTable.setShowGrid(false); termSearchResTable.setGridColor(Color.DARK_GRAY); termSearchResTable.setAutoscrolls(true); termSearchResTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); termSearchResTable.getColumnModel().getColumn(0).setPreferredWidth(80); termSearchResTable.getColumnModel().getColumn(0).setWidth(80); termSearchResTable.getColumnModel().getColumn(0).setCellRenderer(leftRenderer); termSearchResTable.getColumnModel().getColumn(1).setPreferredWidth(120); termSearchResTable.getColumnModel().getColumn(1).setWidth(120); //docSearchResTable.getColumnModel().getColumn(0).setPreferredWidth(50); //docSearchResTable.getColumnModel().getColumn(1).sizeWidthToFit(); }
From source file:v800_trainer.JCicloTronic.java
public void ChangeModel() { setCursor(new Cursor(Cursor.WAIT_CURSOR)); if (Hauptfenster != null) Hauptfenster.setSelectedIndex(0); DataProperty = new java.util.Properties(); jTableaccess = Datentabelle;/*from w w w . ja va2 s. c o m*/ String Filename = ""; String PlaceHolder = " "; File path = new File(Properties.getProperty("data.dir")); final String[] names = { "Datum", "Strecke", "Hhenmeter", "Zeit", "Titel" }; String[] list = path.list(new DirFilter("_Tour.cfg")); RowCount = 0; int Anzahlcfg = 0; if (list != null) Anzahlcfg = list.length; if (Anzahlcfg == 0) { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); return; } Object datab[] = new Object[8]; ArrayList<Object[]> data_list = new ArrayList<Object[]>(); String hmString = ""; DecimalFormat form = new DecimalFormat("0");//Format ohne Kommastelle int j = 0; for (int i = 0; i < Anzahlcfg; i++) { //berprfen ob Hhenmeter eingetragen sind - ansonsten ermitteln (gilt fr neue Dateien) Filename = path.getPath() + SystemProperties.getProperty("file.separator") + list[i]; DataProperty = new java.util.Properties(); try { BufferedInputStream in = new BufferedInputStream(new FileInputStream(Filename)); DataProperty.load(in); in.close(); // prfen ob Datei gezeigt werden soll - Visible = 0 wenn Datei gelscht wurde if (!DataProperty.getProperty("Visible", "1").equalsIgnoreCase("1")) continue; // wenn keine Hhenmeter eingetragen wurden (Erstaufruf) dann Hhenmeter ermitteln if (DataProperty.getProperty("Hoehenmeter", "novalue").equalsIgnoreCase("novalue") && DataProperty.getProperty("Visible", "1").equalsIgnoreCase("1") && !DataProperty.getProperty("Jahr", "keinEintrag").equalsIgnoreCase("keinEintrag")) { JTourData Dummydata = new JTourData(Filename.substring(0, Filename.lastIndexOf('.')), this); DataProperty.setProperty("Hoehenmeter", form.format(Dummydata.ges_Hoehep)); try { Ausgabedatei = new FileOutputStream(Filename); DataProperty.store(Ausgabedatei, "Tour Eigenschaften: " + DataProperty.getProperty("Jahr") + DataProperty.getProperty("Monat") + DataProperty.getProperty("Tag") + DataProperty.getProperty("Stunde") + DataProperty.getProperty("Minute")); Ausgabedatei.close(); } catch (Exception e) { JOptionPane.showMessageDialog(null, " Fehler bei Speichern der DataProperty in ChangeModel", "Achtung!", JOptionPane.ERROR_MESSAGE); } } try { if (Integer.parseInt(DataProperty.getProperty("Visible", "1")) == 1 && !DataProperty.getProperty("Jahr", "keinEintrag").equalsIgnoreCase("keinEintrag")) { datab[0] = new String(" " + DataProperty.getProperty("Tag", "11") + "." + DataProperty.getProperty("Monat", "11") + "." + DataProperty.getProperty("Jahr", "1111")); datab[1] = PlaceHolder.substring(0, 9 - DataProperty.getProperty("Strecke", "0").length()) + DataProperty.getProperty("Strecke", "0") + " "; // data[j][1] = new String(DataProperty.getProperty("Strecke") + " "); datab[2] = new String( " " + HMS(java.lang.Integer.parseInt(DataProperty.getProperty("Dauer", "0")))); datab[3] = new String(DataProperty.getProperty("Titel", "---")); datab[4] = new String(DataProperty.getProperty("Jahr", "1111") + "." + DataProperty.getProperty("Monat", "11") + "." + DataProperty.getProperty("Tag", "11") + "." + DataProperty.getProperty("Stunde", "12") + "." + DataProperty.getProperty("Minute", "59")); datab[5] = new String(Filename.substring(0, Filename.lastIndexOf('.'))); datab[6] = new String(DataProperty.getProperty("Typ", "unbekannt")); hmString = "" + (int) Float.parseFloat(DataProperty.getProperty("Hoehenmeter", "0")); datab[7] = PlaceHolder.substring(0, 9 - hmString.length()) + hmString + " "; data_list.add(datab.clone()); } } catch (Exception e) { JOptionPane.showMessageDialog(null, "Fehler beim Erstellen der Datenliste " + e + " " + j, "Achtung!", JOptionPane.ERROR_MESSAGE); } } catch (Exception e) { System.out.println( "NEW IO-Fehler bei " + path.getPath() + SystemProperties.getProperty("file.separator") + list[i] + "\n " + e + " " + e.getLocalizedMessage() + "--File deleted"); e.printStackTrace(); JOptionPane.showMessageDialog(null, "Fehler beim Einlesen eines cfg Files " + path.getPath() + SystemProperties.getProperty("file.separator") + list[i] + "\n wurde gelscht!", "Achtung!", JOptionPane.ERROR_MESSAGE); File deletefile = new File( path.getPath() + SystemProperties.getProperty("file.separator") + list[i]); if (deletefile.exists()) deletefile.delete(); ChangeModel(); } } TableModel dataModel = new AbstractTableModel() { public int getColumnCount() { return names.length; } @Override public String getColumnName(int column) { return names[column]; } @Override public int getRowCount() { return data_list.size(); } @Override public Object getValueAt(int row, int col) { Object data[] = new Object[8]; data = data_list.get(row); return data[col]; } @Override public void setValueAt(Object Ob, int row, int col) { Object data[] = new Object[8]; data = data_list.get(row); data[col] = Ob; data_list.set(row, data); } }; sorter = new TableSorter(dataModel); DatumColumn = new TableColumn(0); DatumColumn.setHeaderValue(names[0]); DatumColumn.setResizable(false); StreckeColumn = new TableColumn(1); StreckeColumn.setHeaderValue(names[1]); StreckeColumn.setResizable(false); HoeheColumn = new TableColumn(7); HoeheColumn.setHeaderValue(names[2]); HoeheColumn.setResizable(false); ZeitColumn = new TableColumn(2); ZeitColumn.setHeaderValue(names[3]); ZeitColumn.setResizable(false); NotizColumn = new TableColumn(3); NotizColumn.setHeaderValue(names[4]); DatumColumn.setMinWidth((int) 80 * FontSize / 12); StreckeColumn.setMinWidth((int) 65 * FontSize / 12); HoeheColumn.setMinWidth((int) 75 * FontSize / 12); ZeitColumn.setMinWidth((int) 75 * FontSize / 12); NotizColumn.setMinWidth((int) 75 * FontSize / 12); NotizColumn.setPreferredWidth((int) 75 * FontSize / 12 + 1000); DefaultTableCellRenderer TableCell = new DefaultTableCellRenderer(); TableCell.setHorizontalAlignment(JLabel.CENTER); HoeheColumn.setCellRenderer(TableCell); StreckeColumn.setCellRenderer(TableCell); DatumColumn.setCellRenderer(TableCell); ZeitColumn.setCellRenderer(TableCell); HoeheColumn.setHeaderRenderer(TableCell); StreckeColumn.setHeaderRenderer(TableCell); DatumColumn.setHeaderRenderer(TableCell); ZeitColumn.setHeaderRenderer(TableCell); NotizColumn.setHeaderRenderer(TableCell); DefaultTableColumnModel FileTableModel = new DefaultTableColumnModel(); FileTableModel.addColumn(DatumColumn); FileTableModel.addColumn(StreckeColumn); FileTableModel.addColumn(HoeheColumn); FileTableModel.addColumn(ZeitColumn); FileTableModel.addColumn(NotizColumn); Datentabelle.setModel(sorter); Datentabelle.setColumnModel(FileTableModel); Datentabelle.setRowHeight(FontSize + 5); sorter.addMouseListenerToHeaderInTable(Datentabelle); sorter.sortByColumn(0, false); Datentabelle.clearSelection(); SelectionChanged = true; JScrollBar verticaldummy = Datenliste_scroll_Panel.getVerticalScrollBar(); verticaldummy.setPreferredSize(new Dimension(FontSize + 10, FontSize + 10)); Datenliste_scroll_Panel.setVerticalScrollBar(verticaldummy); Update = false; Datenliste_Jahr.removeAllItems(); Datenliste_TourTyp.removeAllItems(); Auswahl_bersicht.removeAllItems(); JahrVergleich.removeAllItems(); InitComboJahr(); InitComboTyp(); Update = true; if (Datentabelle.getRowCount() != 0) { Datentabelle.addRowSelectionInterval(0, 0); Datenliste_scroll_Panel.getViewport().setViewPosition(new java.awt.Point(0, 0)); } if (Uebersicht != null) { Uebersicht = null; } jLabel69_Selektiert.setText(Datentabelle.getSelectedRowCount() + " / " + Datentabelle.getRowCount()); repaint(); setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); }
From source file:app.RunApp.java
/** * Create table of metrics for principal tab * /*from w ww. j ava2 s.co m*/ * @param table Table of metrics * @param jpanel Panel * @param rowData Cell values * @param posx Pos X * @param posy Pos Y * @param width Width * @param height Height */ public void createJTableMetricsPrincipal(JTable table, JPanel jpanel, Object rowData[][], int posx, int posy, int width, int height) { TableModel model = new MetricsTableModel(rowData); table.setModel(model); TableColumnModel tcm = table.getColumnModel(); tcm.getColumn(0).setPreferredWidth(420); tcm.getColumn(1).setPreferredWidth(70); DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer(); rightRenderer.setHorizontalAlignment(JLabel.RIGHT); tcm.getColumn(1).setCellRenderer(rightRenderer); tcm.getColumn(2).setPreferredWidth(50); tcm.getColumn(2).setMaxWidth(50); tcm.getColumn(2).setMinWidth(50); JScrollPane scrollPane = new JScrollPane(table); scrollPane.setBounds(posx, posy, width, height); table.setBorder(BorderFactory.createLineBorder(Color.black)); jpanel.add(scrollPane, BorderLayout.CENTER); jpanel.repaint(); jpanel.validate(); }
From source file:org.fhaes.gui.AnalysisResultsPanel.java
private void setDefaultTableAlignment(int align) { DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setHorizontalAlignment(align); for (int i = 1; i < table.getModel().getColumnCount(); i++) { table.getColumnModel().getColumn(i).setCellRenderer(renderer); }/* w w w. j a va 2s. c o m*/ }
From source file:org.fhaes.gui.AnalysisResultsPanel.java
private void setTableColumnAlignment(int align, int col) { DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setHorizontalAlignment(align); table.getColumnModel().getColumn(col).setCellRenderer(renderer); }
From source file:org.o3project.optsdn.don.frame.NeFrame.java
/** * Create a pane that displays OMS connection information. * //w w w . ja va 2 s. c o m * @return The pane that displays OMS connection information */ private JScrollPane createOmsConnectionInfoPane() { Object[] header = OMS_CONNECTION_INFO_COLNAME_LIST.toArray(); String[][] rowDataList = new String[omsConnectionInfoList.size()][header.length]; for (int i = 0; i < rowDataList.length; i++) { List<Port> omsConnectionInfo = omsConnectionInfoList.get(i); Port port = omsConnectionInfo.get(0); int ofPortIndex = OMS_CONNECTION_INFO_COLNAME_LIST.indexOf(OmsConnectionInfoCols.OF_PORT.getName()); Integer openFlowPortId1 = port.getOpenFlowPortId(); String ofPortValue1; if (openFlowPortId1 == null) { ofPortValue1 = OFPORT_NOTFOUND; } else { ofPortValue1 = String.valueOf(openFlowPortId1); } rowDataList[i][ofPortIndex] = ofPortValue1; Port port2 = omsConnectionInfo.get(1); int connectedToIndex = OMS_CONNECTION_INFO_COLNAME_LIST .indexOf(OmsConnectionInfoCols.CONNECTED_TO.getName()); Integer openFlowPortId2 = port2.getOpenFlowPortId(); String ofPortValue2; if (openFlowPortId2 == null) { ofPortValue2 = OFPORT_NOTFOUND; } else { ofPortValue2 = String.valueOf(openFlowPortId2); } rowDataList[i][connectedToIndex] = port2.getNeId() + ", " + ofPortValue2; } JTable connectedTable = new JTable(rowDataList, header); connectedTable.getTableHeader().setBackground(Color.WHITE); DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setHorizontalAlignment(SwingConstants.CENTER); for (int i = 0; i < header.length; i++) { TableColumn column = connectedTable.getColumnModel().getColumn(i); column.setCellRenderer(renderer); } JScrollPane connectedPane = new JScrollPane(); connectedPane.getViewport().setView(connectedTable); connectedPane.setPreferredSize(new Dimension(connectedPane.getPreferredSize().width, TABLE_HEIGHT)); return connectedPane; }
From source file:org.o3project.optsdn.don.frame.NeFrame.java
/** * Create a pane that displays Information Model ID list. * /* w ww . j av a 2s . com*/ * @param portList Ports * @return The pane that displays Information Model ID list */ private JScrollPane createInformationModelIdListPane(List<Port> portList) { Collections.sort(portList, new PortComparator()); Object[] columnNames = INFORMATION_MODEL_ID_COLNAME_LIST.toArray(); DefaultTableModel tableModel = new DefaultTableModel(columnNames, 0); for (Port port : portList) { Port[] column = { port, port }; tableModel.addRow(column); } JTable informationModeldTable = new JTable(tableModel); informationModeldTable.getTableHeader().setBackground(Color.WHITE); DefaultTableCellRenderer renderer = new InformationModelIdRenderer(); renderer.setHorizontalAlignment(SwingConstants.CENTER); informationModeldTable.setDefaultRenderer(Object.class, renderer); JScrollPane informationModelIdPane = new JScrollPane(); informationModelIdPane.getViewport().setView(informationModeldTable); informationModelIdPane .setPreferredSize(new Dimension(informationModelIdPane.getPreferredSize().width, TABLE_HEIGHT)); return informationModelIdPane; }