public void setColumnWidths() { // See // "http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#custom" int n = getModel().getColumnCount(); for (int j = 0; j < n; ++j) { TableColumn column = getColumnModel().getColumn(j); TableCellRenderer headerRenderer = column.getHeaderRenderer(); if (headerRenderer == null) headerRenderer = getTableHeader().getDefaultRenderer(); // the new 1.3 way Component columnComponent = headerRenderer.getTableCellRendererComponent( this, column.getHeaderValue(), false, false, -1, j); Component cellComponent = getDefaultRenderer(getColumnClass(j)) .getTableCellRendererComponent(this, getModel().getValueAt(0, j), false, false, 0, j); int wantWidth = Math.max( columnComponent.getPreferredSize().width + 10, // fudge factor ... seems to always be too small otherwise (on x86 Linux) cellComponent.getPreferredSize().width + 10 // fudge factor ... seems to always be too small otherwise (on Mac OS X) ); column.setPreferredWidth(wantWidth); } }
public Shell open(Display display) { shell = new Shell(display); shell.setLayout(new FillLayout()); shell.addShellListener( new ShellAdapter() { @Override public void shellClosed(ShellEvent e) { e.doit = closeAddressBook(); } }); createMenuBar(); searchDialog = new SearchDialog(shell); searchDialog.setSearchAreaNames(columnNames); searchDialog.setSearchAreaLabel(resAddressBook.getString("Column")); searchDialog.addFindListener( new FindListener() { public boolean find() { return findEntry(); } }); table = new Table(shell, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); table.setHeaderVisible(true); table.setMenu(createPopUpMenu()); table.addSelectionListener( new SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent e) { TableItem[] items = table.getSelection(); if (items.length > 0) editEntry(items[0]); } }); for (int i = 0; i < columnNames.length; i++) { TableColumn column = new TableColumn(table, SWT.NONE); column.setText(columnNames[i]); column.setWidth(150); final int columnIndex = i; column.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { sort(columnIndex); } }); } newAddressBook(); shell.setSize(table.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, 300); shell.open(); return shell; }
public void cargarTabla() { idCocinerotable.setCellValueFactory(new PropertyValueFactory<Cocinero, Integer>("IdCocinero")); añostable.setCellValueFactory(new PropertyValueFactory<Cocinero, String>("años")); idEmpleadotable.setCellValueFactory(new PropertyValueFactory<Cocinero, Integer>("IdEmpleado")); Service<ObservableList<Cocinero>> service = new Service<ObservableList<Cocinero>>() { @Override protected Task<ObservableList<Cocinero>> createTask() { return new Task<ObservableList<Cocinero>>() { @Override protected ObservableList<Cocinero> call() throws Exception { return FXCollections.observableArrayList(getAllCocinero()); } }; } }; Cocinero.itemsProperty().bind(service.valueProperty()); service.start(); }
public void cargarTabla() { idtable.setCellValueFactory(new PropertyValueFactory<Empleado, Integer>("id")); nombretable.setCellValueFactory(new PropertyValueFactory<Empleado, String>("nombre")); telefonotable.setCellValueFactory(new PropertyValueFactory<Empleado, String>("telf")); // tableView.getItems().setAll(); Service<ObservableList<Empleado>> service = new Service<ObservableList<Empleado>>() { @Override protected Task<ObservableList<Empleado>> createTask() { return new Task<ObservableList<Empleado>>() { @Override protected ObservableList<Empleado> call() throws Exception { return FXCollections.observableArrayList(getAllEmpleados()); } }; } }; Empleados.itemsProperty().bind(service.valueProperty()); service.start(); }
@FXML private void initialize() throws IOException, ParseException { taskNLabel.setVisible(false); nextExecutionLabel.setVisible(false); actveLabel.setVisible(false); initData(); logger.info("Data were initialized"); taskName.setCellValueFactory(new PropertyValueFactory<Task, String>("title")); taskTable.setItems(userData2); taskTable .getSelectionModel() .selectedItemProperty() .addListener( new ChangeListener<Task>() { public void changed( ObservableValue<? extends Task> observable, Task oldValue, Task newValue) { showTaskDetails(newValue); } }); }
public Shell open(Display display) { // Window dressing - the icon windowIcon = new Image(display, getClass().getClassLoader().getResourceAsStream("icons/joanju.gif")); shell = new Shell(display); shell.setLayout(new FillLayout()); shell.addShellListener( new ShellAdapter() { public void shellClosed(ShellEvent e) { e.doit = closeAddressBook(); } }); shell.setImage(windowIcon); createMenuBar(); searchDialog = new SearchDialog(shell); searchDialog.setSearchAreaNames(columnNames); searchDialog.setSearchAreaLabel(resMessages.getString("Column")); searchDialog.addFindListener( new FindListener() { public boolean find() { return findEntry(); } }); table = new Table(shell, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); table.setHeaderVisible(true); table.setMenu(createPopUpMenu()); table.addSelectionListener( new SelectionAdapter() { public void widgetDefaultSelected(SelectionEvent e) { TableItem[] items = table.getSelection(); if (items.length > 0) launchEditor(items[0]); } }); int[] widths = {150, 50, 200, 200}; for (int i = 0; i < columnNames.length; i++) { TableColumn column = new TableColumn(table, SWT.NONE); column.setText(columnNames[i]); column.setWidth(widths[i]); final int columnIndex = i; column.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { sort(columnIndex); } }); } newAddressBook(); shell.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { windowIcon.dispose(); } }); shell.setSize(table.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, 300); shell.open(); return shell; }
private TableColumn genColumn(int modelIndex, int width, String label) { TableColumn tc = new TableColumn(modelIndex, width); tc.setHeaderValue(label); return tc; }
private void openFile(String fileName, Table table) { String outStr; try { CSVReader reader = new CSVReader(new FileReader(fileName), ',', '"'); String[] strLineArr; // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream(fileName); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; table.clearAll(); table.removeAll(); table.redraw(); int length = 0; boolean first = true; // Read File Line By Line while ((strLineArr = reader.readNext()) != null) { // while ((strLine = br.readLine()) != null) { // Print the content on the console // outStr = strLine; TableItem item = null; if (first) { length = strLineArr.length; } else { item = new TableItem(table, SWT.NONE); } int thisLen = strLineArr.length; if (thisLen <= length) { // String[] line = new String[length]; for (int i = 0; i < thisLen; i++) { // line[i] = st.nextToken(); // item.setText (i, st.nextToken()); if (first) { TableColumn column = new TableColumn(table, SWT.NONE); column.setText(strLineArr[i]); } else { // System.out.println("-- "+i+" -- " + strLineArr[i]); item.setText(i, strLineArr[i]); } } } first = false; } // System.out.println("Finisehd file"); for (int i = 0; i < length; i++) { table.getColumn(i).pack(); } // System.out.println("finished packing"); // Close the input stream in.close(); } catch (Exception e) { // Catch exception if any System.err.println("Error: " + e.getMessage()); e.printStackTrace(); } }