List of usage examples for javax.swing.table JTableHeader setPreferredSize
@BeanProperty(preferred = true, description = "The preferred size of the component.") public void setPreferredSize(Dimension preferredSize)
From source file:com.sec.ose.osi.ui.frm.main.manage.AddProjectTableModel.java
public void setColumnView(JTable table) { table.setShowVerticalLines(false);/* ww w .ja va 2 s . c om*/ table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setColumnSelectionAllowed(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); table.setRowHeight(30); JTableHeader header = table.getTableHeader(); header.setPreferredSize(new java.awt.Dimension(table.getTableHeader().getWidth(), 30)); header.setFont(new Font("Arial", Font.BOLD, 12)); header.setReorderingAllowed(false); TableColumnModel cm = table.getColumnModel(); TableColumn col = null; searchHeader = new CheckBoxHeader(new CheckboxHeaderItemListener(table, COL_ISSELECT), ""); col = cm.getColumn(COL_ISSELECT); col.setHeaderRenderer(searchHeader); }
From source file:com.sec.ose.osi.ui.frm.main.manage.ManagedProjectTableModel.java
public void setColumnType(JTable table) { table.setShowVerticalLines(false);//w w w. j a v a2 s . c o m table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setRowHeight(30); JTableHeader header = table.getTableHeader(); header.setPreferredSize(new java.awt.Dimension(table.getTableHeader().getWidth(), 30)); header.setFont(new Font("Arial", Font.BOLD, 12)); header.setReorderingAllowed(false); TableColumnModel cm = table.getColumnModel(); TableColumn col = null; analyzeHeader = new CheckBoxHeader(new CheckboxHeaderItemListener(table, COL_ANALYZE_TARGET), "Analyze Target"); col = cm.getColumn(COL_ANALYZE_TARGET); col.setHeaderRenderer(analyzeHeader); JCheckBox chkbox = new JCheckBox(); chkbox.setBackground(Color.white); chkbox.setHorizontalAlignment(JLabel.CENTER); col.setCellRenderer(new DefaultTableCellRenderer() { private static final long serialVersionUID = 1L; public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { ManagedProjectTableModel model = (ManagedProjectTableModel) table.getModel(); String sPrjName = (String) table.getValueAt(row, ManagedProjectTableModel.COL_PROJECT_NAME); OSIProjectInfo item = model.getProjectInfo(sPrjName); JCheckBox chkbox = new JCheckBox(); chkbox.setSelected(((Boolean) value).booleanValue()); if (item != null) { chkbox.setEnabled(item.isLocationValid()); } chkbox.setHorizontalAlignment(JLabel.CENTER); chkbox.setBackground(Color.white); return (Component) chkbox; } }); col.setCellEditor(new DefaultCellEditor(chkbox)); col = cm.getColumn(COL_ANALYZE_STATUS); col.setCellRenderer(new StatusIconCellRenderer()); col = cm.getColumn(COL_SOURCE_LOCATION); col.setCellRenderer(new FileBrowseCellRenderer()); col.setCellEditor(new FileBrowseCellEditor()); }
From source file:com.projity.pm.graphic.spreadsheet.SpreadSheet.java
public void setModel(SpreadSheetModel spreadSheetModel, SpreadSheetColumnModel spreadSheetColumnModel) { makeCustomTableHeader(spreadSheetColumnModel); TableModel oldModel = getModel(); setModel(spreadSheetModel);/*from w ww. j a v a 2s.c o m*/ if (spreadSheetColumnModel != null) { //System.out.println("creating new ColModel"); setColumnModel(spreadSheetColumnModel); selection = new SpreadSheetSelectionModel(this); selection.setRowSelection(new SpreadSheetListSelectionModel(selection, true)); selection.setColumnSelection(new SpreadSheetListSelectionModel(selection, false)); setSelectionModel(selection.getRowSelection()); createDefaultColumnsFromModel(spreadSheetModel.getFieldArray()); //Consume memory getColumnModel().setSelectionModel(selection.getColumnSelection()); } registerEditors(); //Consume memory initRowHeader(spreadSheetModel); initModel(); initListeners(); GraphicConfiguration config = GraphicConfiguration.getInstance(); //fix for substance setTableHeader(createDefaultTableHeader()); JTableHeader header = getTableHeader(); header.setPreferredSize( new Dimension((int) header.getPreferredSize().getWidth(), config.getColumnHeaderHeight())); header.addMouseListener(new HeaderMouseListener(this)); addMouseListener(new MouseAdapter() { // Cursor oldCursor = null; // public void mouseEntered(MouseEvent e) { // Point p = e.getPoint(); // int col = columnAtPoint(p); // Field field = ((SpreadSheetModel) getModel()).getFieldInNonTranslatedColumn(col + 1); // System.out.println("mouse entered field " + field); // if (field != null && field.isHyperlink()) { // oldCursor = getCursor(); // setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); // System.out.println("setting new cursor to " + Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) + " old is " + oldCursor); // } else // super.mouseEntered(e); // // } // // public void mouseExited(MouseEvent e) { // Point p = e.getPoint(); // int col = columnAtPoint(p); // Field field = ((SpreadSheetModel) getModel()).getFieldInNonTranslatedColumn(col + 1); // System.out.println("mouse exited field " + field); // if (field != null && field.isHyperlink()) { // setCursor(oldCursor); // System.out.println("setting old cursor to " + oldCursor); // e.consume(); // } else // super.mouseEntered(e); // } public void mousePressed(MouseEvent e) { // changed to mousePressed instead of mouseClicked() for snappier handling 17/5/04 hk Point p = e.getPoint(); int row = rowAtPoint(p); int col = columnAtPoint(p); SpreadSheetPopupMenu popup = getPopup(); if (SwingUtilities.isLeftMouseButton(e)) { SpreadSheetColumnModel columnModel = (SpreadSheetColumnModel) getColumnModel(); Field field = ((SpreadSheetModel) getModel()).getFieldInNonTranslatedColumn(col + 1); SpreadSheetModel model = (SpreadSheetModel) getModel(); if (field.isNameField()) { // if (col == columnModel.getNameIndex()) { GraphicNode node = model.getNode(row); if (isOnIcon(e)) { if (model.getCellProperties(node).isCompositeIcon()) { finishCurrentOperations(); selection.getRowSelection().clearSelection(); boolean change = true; if (!node.isFetched()) // for subprojects change = node.fetch(); if (change) model.changeCollapsedState(row); e.consume(); // prevent dbl click treatment below // because editor may have already been // installed we // have to update its collapsed state // updateNameCellEditor(node); // editCellAt(row,model.findGraphicNodeRow(node)); } } } else if (field != null && field.isHyperlink()) { Hyperlink link = (Hyperlink) model.getValueAt(row, col + 1); if (link != null) { BrowserControl.displayURL(link.getAddress()); e.consume(); // prevent dbl click treatment below } } if (!e.isConsumed()) { if (e.getClickCount() == 2) // if above code didn't treat and is dbl click doDoubleClick(row, col); else doClick(row, col); } } else if (popup != null && SwingUtilities.isRightMouseButton(e)) { // e.isPopupTrigger() can be used too // selection.getRowSelection().clearSelection(); // selection.getRowSelection().addSelectionInterval(row, row); popup.setRow(row); popup.setCol(col); popup.show(SpreadSheet.this, e.getX(), e.getY()); } } }); if (oldModel != spreadSheetModel && oldModel instanceof CommonSpreadSheetModel) ((CommonSpreadSheetModel) getModel()).getCache().removeNodeModelListener(this); spreadSheetModel.getCache().addNodeModelListener(this); // getColumnModel().addColumnModelListener(new TableColumnModelListener(){ // public void columnAdded(TableColumnModelEvent e) { // // TODO Auto-generated method stub // // } // public void columnMarginChanged(ChangeEvent e) { // // TODO Auto-generated method stub // // } // public void columnMoved(TableColumnModelEvent e) { // // TODO Auto-generated method stub // // } // public void columnRemoved(TableColumnModelEvent e) { // // TODO Auto-generated method stub // // } // public void columnSelectionChanged(ListSelectionEvent e) { // System.out.println(((e.getValueIsAdjusting())?"lse=":"LSE=")+e.getFirstIndex()+", "+e.getLastIndex()); // SpreadSheet.this.revalidate(); // //SpreadSheet.this.paintImmediately(0, 0, getWidth(), GraphicConfiguration.getInstance().getColumnHeaderHeight()); // } // }); }
From source file:com.projity.pm.graphic.spreadsheet.SpreadSheet.java
public void resizeAndRepaintHeader() { JTableHeader header = getTableHeader(); SpreadSheetColumnModel tm = ((SpreadSheetColumnModel) getColumnModel()); int colWidth = tm.getColWidth();// tm.getTotalColumnWidth(); //Hack, // colWidth isn't enough why? header.setPreferredSize(new Dimension(colWidth, header.getPreferredSize().height)); header.resizeAndRepaint();/*w w w . ja va 2 s . c o m*/ }
From source file:org.agmip.ui.afsirs.frames.SWFrame.java
public SWFrame(JFrame prev) { initComponents();/* w ww .jav a 2s . c o m*/ this.prev = prev; setLocation(400, 50); utils = AFSIRSUtils.getInstance(); ir = utils.getIrrigationSystem(); DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer(); centerRenderer.setHorizontalAlignment(JLabel.CENTER); soilTable.setDefaultRenderer(Double.class, centerRenderer); soilTable.setDefaultRenderer(Integer.class, centerRenderer); infoButton.setForeground(Color.blue); infoButton.setBorder(LineBorder.createGrayLineBorder()); JTableHeader tHeader = soilTable.getTableHeader(); tHeader.setPreferredSize(new Dimension(300, 35)); wcErrorLabel.setVisible(false); errorLabel.setVisible(false); init(); if (AFSIRSUtils.defaultMode) { dwtText.setText(60.0 + ""); soilListBox.setSelectedIndex(5); waterholdcapacityBox.setSelectedIndex(waterHoldSelectedItemIndex[0]); } getRootPane().setDefaultButton(nextButton); }
From source file:com.itemanalysis.jmetrik.gui.Jmetrik.java
public Jmetrik() { super("jMetrik"); setPreferredSize(new Dimension(1024, 650)); setDefaultCloseOperation(EXIT_ON_CLOSE); //properly close database if user closes window this.addWindowListener(new WindowAdapter() { @Override//from w w w . ja v a 2s. c om public void windowClosing(WindowEvent we) { if (workspace != null) { workspace.closeDatabase(); } System.exit(0); } }); //add statusbar statusBar = new StatusBar(1024, 30); statusBar.setBorder(new EmptyBorder(2, 2, 2, 2)); getContentPane().add(statusBar, BorderLayout.SOUTH); //start logging startLog(); //left-right splitpane JSplitPane splitPane1 = new JSplitPane(); splitPane1.setDividerLocation(200); //setup workspace list workspaceList = new JList(); workspaceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); workspaceList.setModel(new SortedListModel<DataTableName>()); workspaceList.addKeyListener(new DeleteKeyListener()); // workspaceList.getInsets().set(5, 5, 5, 5); //add icon to list cell renderer String urlString = "/images/spreadsheet.png"; URL url = this.getClass().getResource(urlString); final ImageIcon tableIcon = new ImageIcon(url, "Table"); workspaceList.setCellRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); label.setIcon(tableIcon); return label; } }); JScrollPane scrollPane1 = new JScrollPane(workspaceList); scrollPane1.setPreferredSize(new Dimension(200, 698)); splitPane1.setLeftComponent(scrollPane1); //tabbed pane for top pane tabbedPane = new JTabbedPane(); tabbedPane.setTabPlacement(JTabbedPane.BOTTOM); //setup data table dataTable = new DataTable(); dataTable.setRowHeight(18); //change size of table header and center text JTableHeader header = dataTable.getTableHeader(); header.setDefaultRenderer(new TableHeaderCellRenderer()); JScrollPane dataScrollPane = new JScrollPane(dataTable); tabbedPane.addTab("Data", dataScrollPane); //setup variable table variableTable = new DataTable(); variableTable.setRowHeight(18); variableTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { super.mouseClicked(e); if (e.getClickCount() == 2) { JTable target = (JTable) e.getSource(); int row = target.getSelectedRow(); int col = target.getSelectedColumn(); if (col == 0) { if (target.getModel() instanceof VariableModel) { VariableModel vModel = (VariableModel) target.getModel(); String s = (String) vModel.getValueAt(row, col); DatabaseName db = workspace.getDatabaseName(); DataTableName table = workspace.getCurrentDataTable(); RenameVariableDialog renameVariableDialog = new RenameVariableDialog(Jmetrik.this, db, table, s); renameVariableDialog.setVisible(true); if (renameVariableDialog.canRun()) { RenameVariableCommand command = renameVariableDialog.getCommand(); workspace.runProcess(command); } } //end instanceof } //end if col==0 } //end if click count==2 }//end mouse clicked }); //change size of table header and center text JTableHeader variableHeader = variableTable.getTableHeader(); variableHeader.setDefaultRenderer(new TableHeaderCellRenderer()); variableHeader.setPreferredSize(new Dimension(30, 21)); JScrollPane variableScrollPane = new JScrollPane(variableTable); tabbedPane.addTab("Variables", variableScrollPane); splitPane1.setRightComponent(tabbedPane); getContentPane().add(splitPane1, BorderLayout.CENTER); //add status bar listener - needed to display status message that are generated within this class this.addPropertyChangeListener(statusBar.getStatusListener()); //add listener for displaying error messages - needed to display errors and exceptions this.addPropertyChangeListener(new ErrorOccurredPropertyChangeListener()); //instantiate file utilities fileUtils = new JmetrikFileUtils(); fileUtils.addPropertyChangeListener(statusBar.getStatusListener()); //set import and export path to user's documents folder JFileChooser chooser = new JFileChooser(); FileSystemView fw = chooser.getFileSystemView(); importExportPath = fw.getDefaultDirectory().toString().replaceAll("\\\\", "/"); //create and start a workspace startWorkspace(); //create menu bar and tool bar this.setJMenuBar(createMenuBar()); JToolBar toolBar = createToolBar(); toolBar.setFloatable(false); toolBar.setRollover(true); getContentPane().add(toolBar, BorderLayout.PAGE_START); pack(); }
From source file:semaforo.Semaforo.java
public synchronized void loadTableTickers() { Settings settings = Controller.getSettings(); CustomRenderer cr = new CustomRenderer(TableTicker.getDefaultRenderer(Object.class), Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY); TableTicker.setDefaultRenderer(Object.class, cr); DefaultTableModel model = (DefaultTableModel) TableTicker.getModel(); TableTicker.setRowHeight(20); //40 TableTicker.setFont(new Font("Arial", Font.BOLD, 12)); //18 TableTicker.getColumnModel().getColumn(0).setPreferredWidth(10); TableTicker.getColumnModel().getColumn(1).setPreferredWidth(30); JTableHeader header = TableTicker.getTableHeader(); header.setPreferredSize(new Dimension(100, 30)); TableTicker.getTableHeader().setFont(new Font("Arial", Font.BOLD, 15)); Object[] o = new Object[2]; for (int i = 0; i < settings.getTickers().size(); i++) { o[0] = settings.getTickers().get(i).getName(); o[1] = 0;/*ww w. ja va2 s .c om*/ model.addRow(o); } }
From source file:semaforo.Semaforo.java
public synchronized void loadTableWeek(JTable TableWeek, int index) { Settings settings = Controller.getSettings(); //TableWeek.getColumnModel().getColumn(0).setPreferredWidth(350); //150 TableWeek.setRowHeight(20); //40 //TableWeek.getColumnModel().getColumn(9).setPreferredWidth(350);//150 TableWeek.setFont(new Font("Arial", Font.BOLD, 12));//18 CustomRenderer cr = new CustomRenderer(TableWeek.getDefaultRenderer(Object.class), Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY); TableWeek.setDefaultRenderer(Object.class, cr); DefaultTableModel model = (DefaultTableModel) TableWeek.getModel(); Object[] o = new Object[10]; JTableHeader header = TableWeek.getTableHeader(); header.setPreferredSize(new Dimension(10, 30)); //100 TableWeek.getTableHeader().setFont(new Font("Arial", Font.BOLD, 15)); /* DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer(); centerRenderer.setHorizontalAlignment(SwingConstants.CENTER); TableWeek.getColumnModel().getColumn(0).setCellRenderer(centerRenderer); TableWeek.getColumnModel().getColumn(9).setCellRenderer(centerRenderer); TableWeek.setDefaultRenderer(String.class, centerRenderer);*/ int num = settings.getTickers().size(); /* while(DDBB.loadData) { try {// www. j a v a 2s.c o m Thread.sleep(500); } catch (InterruptedException ex) { Logger.getLogger(Semaforo.class.getName()).log(Level.SEVERE, null, ex); } }*/ if (TableWeek.getModel().getRowCount() > 0) { num = Math.min(settings.getTickers().size(), TableWeek.getModel().getRowCount()); } for (int i = 0; i < num; i++) { o[0] = settings.getTickers().get(i).getMinValue(index); o[9] = settings.getTickers().get(i).getMaxValue(index); model.addRow(o); } }
From source file:org.apache.cayenne.modeler.editor.AbstractCallbackMethodsTab.java
private void addButtonAtHeader(JTable table, JButton button, ActionListener buttonListener, ImageIcon buttonIcon) {/* www.j a va 2s. c o m*/ PanelBuilder builder = new PanelBuilder(new FormLayout("left:10dlu, 2dlu", "center:10dlu")); CellConstraints cc = new CellConstraints(); button.setIcon(buttonIcon); button.setOpaque(false); button.setBorderPainted(false); button.setContentAreaFilled(false); button.addActionListener(buttonListener); builder.add(button, cc.xy(1, 1)); JPanel buttonPanel = builder.getPanel(); buttonPanel.setOpaque(false); JTableHeader header = table.getTableHeader(); header.setLayout(new BorderLayout()); header.setReorderingAllowed(false); header.setPreferredSize(new Dimension(150, 20)); header.add(buttonPanel, BorderLayout.EAST); }