List of usage examples for javax.swing JScrollPane setRowHeader
@BeanProperty(expert = true, description = "The row header child for this scrollpane") public void setRowHeader(JViewport rowHeader)
null
, syncs the y coordinate of its viewPosition with the viewport (if there is one) and then adds it to the scroll pane. From source file:MainClass.java
public MainClass() { super("Row Header Test"); setSize(300, 200);//from w w w . ja va 2 s . com 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:RowHeaderTable.java
public RowHeaderTable() { super("Row Header Test"); setSize(300, 200);//from w ww . j a v a2 s. 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]; } // 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); }
From source file:com.projity.pm.graphic.chart.TimeChartPanel.java
public void configureScrollPaneHeaders(JScrollPane scrollPane, JComponent rowHeader) { viewport = scrollPane.getViewport(); if (viewport == null || viewport.getView() != this) return;/*w w w . ja v a2s . c o m*/ JViewport vp = new JViewport(); vp.setView(rowHeader); vp.setPreferredSize(rowHeader.getPreferredSize()); scrollPane.setRowHeader(vp); scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, new ChartCorner(this)); Border border = scrollPane.getBorder(); if (border == null || border instanceof UIResource) { scrollPane.setBorder(UIManager.getBorder("Table.scrollPaneBorder")); } // left scale synchro viewport.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { updateTimeScaleComponentSize(); } }); }
From source file:com.projity.pm.graphic.spreadsheet.common.CommonSpreadSheet.java
protected void configureScrollPaneHeaders(JScrollPane scrollPane) { if (scrollPane instanceof ScaledScrollPane) scrollPane.setColumnHeaderView(((ScaledScrollPane) scrollPane).getTimeScaleComponent()); else/*from w ww .ja v a 2 s. c o m*/ scrollPane.setColumnHeaderView(getTableHeader()); JViewport vp = new JViewport(); vp.setView(rowHeader); vp.setPreferredSize(rowHeader.getPreferredSize()); scrollPane.setRowHeader(vp); corner = new SpreadSheetCorner(this); scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, corner); //scrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER,new GradientCorner()); }
From source file:ro.nextreports.designer.util.TableUtil.java
/** * Creates row header for table with row number (starting with 1) displayed. *///w ww.j a v a 2 s .co m public static void removeRowHeader(JTable table) { Container p = table.getParent(); if (p instanceof JViewport) { Container gp = p.getParent(); if (gp instanceof JScrollPane) { JScrollPane scrollPane = (JScrollPane) gp; scrollPane.setRowHeader(null); } } }