List of usage examples for javax.swing JScrollPane setCorner
public void setCorner(String key, Component corner)
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;//from w w w . ja v a 2 s . 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:AccessibleScrollDemo.java
public AccessibleScrollDemo() { //Load the photograph into an image icon. ImageIcon david = new ImageIcon("images/youngdad.jpeg"); david.setDescription("Photograph of David McNabb in his youth."); //Create the row and column headers columnView = new Rule(Rule.HORIZONTAL, true); columnView.setPreferredWidth(david.getIconWidth()); columnView.getAccessibleContext().setAccessibleName("Column Header"); columnView.getAccessibleContext()// ww w .j a v a 2 s .c om .setAccessibleDescription("Displays horizontal ruler for " + "measuring scroll pane client."); rowView = new Rule(Rule.VERTICAL, true); rowView.setPreferredHeight(david.getIconHeight()); rowView.getAccessibleContext().setAccessibleName("Row Header"); rowView.getAccessibleContext() .setAccessibleDescription("Displays vertical ruler for " + "measuring scroll pane client."); //Create the corners JPanel buttonCorner = new JPanel(); isMetric = new JToggleButton("cm", true); isMetric.setFont(new Font("SansSerif", Font.PLAIN, 11)); isMetric.setMargin(new Insets(2, 2, 2, 2)); isMetric.addItemListener(new UnitsListener()); isMetric.setToolTipText("Toggles rulers' unit of measure " + "between inches and centimeters."); buttonCorner.add(isMetric); //Use the default FlowLayout buttonCorner.getAccessibleContext().setAccessibleName("Upper Left Corner"); String desc = "Fills the corner of a scroll pane " + "with color for aesthetic reasons."; Corner lowerLeft = new Corner(); lowerLeft.getAccessibleContext().setAccessibleName("Lower Left Corner"); lowerLeft.getAccessibleContext().setAccessibleDescription(desc); Corner upperRight = new Corner(); upperRight.getAccessibleContext().setAccessibleName("Upper Right Corner"); upperRight.getAccessibleContext().setAccessibleDescription(desc); //Set up the scroll pane picture = new ScrollablePicture(david, columnView.getIncrement()); picture.setToolTipText(david.getDescription()); picture.getAccessibleContext().setAccessibleName("Scroll pane client"); JScrollPane pictureScrollPane = new JScrollPane(picture); pictureScrollPane.setPreferredSize(new Dimension(300, 250)); pictureScrollPane.setViewportBorder(BorderFactory.createLineBorder(Color.black)); pictureScrollPane.setColumnHeaderView(columnView); pictureScrollPane.setRowHeaderView(rowView); pictureScrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, buttonCorner); pictureScrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER, lowerLeft); pictureScrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, upperRight); //Put it in this panel setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); add(pictureScrollPane); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:components.ScrollDemo.java
public ScrollDemo() { setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); //Get the image to use. ImageIcon bee = createImageIcon("images/flyingBee.jpg"); //Create the row and column headers. columnView = new Rule(Rule.HORIZONTAL, true); rowView = new Rule(Rule.VERTICAL, true); if (bee != null) { columnView.setPreferredWidth(bee.getIconWidth()); rowView.setPreferredHeight(bee.getIconHeight()); } else {// w w w . java 2 s. co m columnView.setPreferredWidth(320); rowView.setPreferredHeight(480); } //Create the corners. JPanel buttonCorner = new JPanel(); //use FlowLayout isMetric = new JToggleButton("cm", true); isMetric.setFont(new Font("SansSerif", Font.PLAIN, 11)); isMetric.setMargin(new Insets(2, 2, 2, 2)); isMetric.addItemListener(this); buttonCorner.add(isMetric); //Set up the scroll pane. picture = new ScrollablePicture(bee, columnView.getIncrement()); JScrollPane pictureScrollPane = new JScrollPane(picture); pictureScrollPane.setPreferredSize(new Dimension(300, 250)); pictureScrollPane.setViewportBorder(BorderFactory.createLineBorder(Color.black)); pictureScrollPane.setColumnHeaderView(columnView); pictureScrollPane.setRowHeaderView(rowView); //Set the corners. //In theory, to support internationalization you would change //UPPER_LEFT_CORNER to UPPER_LEADING_CORNER, //LOWER_LEFT_CORNER to LOWER_LEADING_CORNER, and //UPPER_RIGHT_CORNER to UPPER_TRAILING_CORNER. In practice, //bug #4467063 makes that impossible (in 1.4, at least). pictureScrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, buttonCorner); pictureScrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER, new Corner()); pictureScrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, new Corner()); //Put it in this panel. add(pictureScrollPane); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:misc.AccessibleScrollDemo.java
public AccessibleScrollDemo() { // Get the image to use. ImageIcon bee = createImageIcon("images/flyingBee.jpg", "Photograph of a flying bee."); // Create the row and column headers. columnView = new Rule(Rule.HORIZONTAL, true); if (bee != null) { columnView.setPreferredWidth(bee.getIconWidth()); } else {//from ww w . j a v a2 s .com columnView.setPreferredWidth(320); } columnView.getAccessibleContext().setAccessibleName("Column Header"); columnView.getAccessibleContext() .setAccessibleDescription("Displays horizontal ruler for " + "measuring scroll pane client."); rowView = new Rule(Rule.VERTICAL, true); if (bee != null) { rowView.setPreferredHeight(bee.getIconHeight()); } else { rowView.setPreferredHeight(480); } rowView.getAccessibleContext().setAccessibleName("Row Header"); rowView.getAccessibleContext() .setAccessibleDescription("Displays vertical ruler for " + "measuring scroll pane client."); // Create the corners. JPanel buttonCorner = new JPanel(); isMetric = new JToggleButton("cm", true); isMetric.setFont(new Font("SansSerif", Font.PLAIN, 11)); isMetric.setMargin(new Insets(2, 2, 2, 2)); isMetric.addItemListener(this); isMetric.setToolTipText("Toggles rulers' unit of measure " + "between inches and centimeters."); buttonCorner.add(isMetric); //Use the default FlowLayout buttonCorner.getAccessibleContext().setAccessibleName("Upper Left Corner"); String desc = "Fills the corner of a scroll pane " + "with color for aesthetic reasons."; Corner lowerLeft = new Corner(); lowerLeft.getAccessibleContext().setAccessibleName("Lower Left Corner"); lowerLeft.getAccessibleContext().setAccessibleDescription(desc); Corner upperRight = new Corner(); upperRight.getAccessibleContext().setAccessibleName("Upper Right Corner"); upperRight.getAccessibleContext().setAccessibleDescription(desc); // Set up the scroll pane. picture = new ScrollablePicture(bee, columnView.getIncrement()); picture.setToolTipText(bee.getDescription()); picture.getAccessibleContext().setAccessibleName("Scroll pane client"); JScrollPane pictureScrollPane = new JScrollPane(picture); pictureScrollPane.setPreferredSize(new Dimension(300, 250)); pictureScrollPane.setViewportBorder(BorderFactory.createLineBorder(Color.black)); pictureScrollPane.setColumnHeaderView(columnView); pictureScrollPane.setRowHeaderView(rowView); // In theory, to support internationalization you would change // UPPER_LEFT_CORNER to UPPER_LEADING_CORNER, // LOWER_LEFT_CORNER to LOWER_LEADING_CORNER, and // UPPER_RIGHT_CORNER to UPPER_TRAILING_CORNER. In practice, // bug #4467063 makes that impossible (at least in 1.4.0). pictureScrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, buttonCorner); pictureScrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER, lowerLeft); pictureScrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, upperRight); // Put it in this panel. setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); add(pictureScrollPane); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:com.diversityarrays.kdxplore.trials.TrialSelectionDialog.java
@SuppressWarnings("rawtypes") @Override//from w w w .j a v a2s . c om protected Component createMainPanel() { CheckSelectionButtonsPanel csbp = new CheckSelectionButtonsPanel(CheckSelectionButtonsPanel.ALL, trialRecordTable); csbp.addUncheckAllActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { trialRecordTableModel.clearChosen(); } }); csbp.addCheckAllActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { trialRecordTableModel.chooseAll(); } }); csbp.addCheckSelectedActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Integer> selectedModelRows = GuiUtil.getSelectedModelRows(trialRecordTable); trialRecordTableModel.addChosenRows(selectedModelRows); } }); csbp.addCheckUnselectedActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Set<Integer> selectedModelRows = new HashSet<>(GuiUtil.getSelectedModelRows(trialRecordTable)); if (selectedModelRows.isEmpty()) { trialRecordTableModel.chooseAll(); } else { List<Integer> rowsToChoose = new ArrayList<>(); for (int mrow = trialRecordTable.getRowCount(); --mrow >= 0;) { if (!selectedModelRows.contains(mrow)) { rowsToChoose.add(mrow); } } trialRecordTableModel.addChosenRows(rowsToChoose); } } }); Box buttons = Box.createHorizontalBox(); buttons.add(Box.createHorizontalGlue()); buttons.add(new JLabel("Select one or more and click '" + USE_TRIALS + "'")); buttons.add(csbp); buttons.add(Box.createHorizontalGlue()); List<TableColumn> columns = DartEntityTableModel.collectNamedColumns(trialRecordTable, trialRecordTableModel, true, "TrialName", "Site", "# Plots", "# Measurements", "Design", "Manager", "TrialType", "Project", "Start Date"); // List<TableColumn> columns = DartEntityTableModel.collectNonExpertColumns(trialRecordTable, trialRecordTableModel, true); Map<String, TableColumn[]> choices = new HashMap<>(); choices.put(INITIAL_COLUMNS_TAGNAME, columns.toArray(new TableColumn[columns.size()])); TableColumnSelectionButton tcsb = new TableColumnSelectionButton(trialRecordTable, choices); tcsb.setSelectedColumns(INITIAL_COLUMNS_TAGNAME); trialRecordTable.setRowSorter(new TableRowSorter<DartEntityTableModel>(trialRecordTableModel)); JScrollPane scrollPane = new JScrollPane(trialRecordTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, tcsb); JPanel trialsPanel = new JPanel(new BorderLayout()); trialsPanel.add(messageLabel, BorderLayout.NORTH); trialsPanel.add(scrollPane, BorderLayout.CENTER); trialsPanel.add(buttons, BorderLayout.SOUTH); cardPanel.add(helpInstructions, CARD_HELP); cardPanel.add(trialsPanel, CARD_TRIALS); cardLayout.show(cardPanel, CARD_HELP); splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, searchOptionsPanel.getViewComponent(), cardPanel); return splitPane; }
From source file:PagingTester.java
public static JScrollPane createPagingScrollPaneForTable(JTable jt) { JScrollPane jsp = new JScrollPane(jt); TableModel tmodel = jt.getModel(); // Don't choke if this is called on a regular table . . . if (!(tmodel instanceof PagingModel)) { return jsp; }/* w w w . ja v a2 s .c o m*/ // Okay, go ahead and build the real scrollpane final PagingModel model = (PagingModel) tmodel; final JButton upButton = new JButton(new ArrowIcon(ArrowIcon.UP)); upButton.setEnabled(false); // starts off at 0, so can't go up final JButton downButton = new JButton(new ArrowIcon(ArrowIcon.DOWN)); if (model.getPageCount() <= 1) { downButton.setEnabled(false); // One page...can't scroll down } upButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { model.pageUp(); // If we hit the top of the data, disable the up button. if (model.getPageOffset() == 0) { upButton.setEnabled(false); } downButton.setEnabled(true); } }); downButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { model.pageDown(); // If we hit the bottom of the data, disable the down button. if (model.getPageOffset() == (model.getPageCount() - 1)) { downButton.setEnabled(false); } upButton.setEnabled(true); } }); // Turn on the scrollbars; otherwise we won't get our corners. jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); // Add in the corners (page up/down). jsp.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, upButton); jsp.setCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER, downButton); return jsp; }
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 w w.jav a 2s . co 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:com.diversityarrays.kdxplore.curate.fieldview.FieldLayoutViewPanel.java
@SuppressWarnings("unchecked") public FieldLayoutViewPanel(@SuppressWarnings("rawtypes") MutableComboBoxModel comboBoxModel, JCheckBox alwaysOnTopOption, CurationData cd, CurationTableModel ctm, SelectedValueStore svs, PlotCellChoicesPanel pccp, JPopupMenu popuMenu, Font fontForResizeControls, Action curationHelpAction, MessagePrinter mp, Closure<String> selectionClosure, CurationContext curationContext, CurationMenuProvider curationMenuProvider, FieldLayoutTableModel fieldLayoutTableModel, CellSelectableTable fieldLayoutTable, FieldViewSelectionModel fvsm,// w w w. ja v a2 s .com JButton undockButton) { super(new BorderLayout()); this.traitInstanceCombo.setModel(comboBoxModel); this.curationData = cd; this.messagePrinter = mp; this.selectionClosure = selectionClosure; this.curationTableModel = ctm; this.fieldLayoutTableModel = fieldLayoutTableModel; this.fieldLayoutTable = fieldLayoutTable; this.fieldViewSelectionModel = fvsm; traitInstanceCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Object item = comboBoxModel.getSelectedItem(); if (item instanceof TraitInstance) { TraitInstance ti = (TraitInstance) item; plotCellRenderer.setActiveInstance(ti); } } }); rhtm = new RowHeaderTableModel(true, fieldLayoutTable, rowRemovable) { public String getRowLabel(int rowIndex) { int yCoord = FieldLayoutUtil.convertRowIndexToYCoord(rowIndex, trial, fieldLayoutTableModel.getFieldLayout()); return String.valueOf(yCoord); } }; rowHeaderTable = new RowHeaderTable(SwingConstants.CENTER, false, fieldLayoutTable, rowRemovable, rhtm, RowHeaderTable.createDefaultColumnModel("X/Y")) { public String getMarkerIndexName(int viewRow) { return "MIN-" + viewRow; //$NON-NLS-1$ } }; rhtTableRowResizer = new TableRowResizer(rowHeaderTable, true); curationData.addCurationDataChangeListener(plotActivationListener); curationTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { fieldLayoutTable.repaint(); } }); plotCellRenderer = new PlotCellRenderer(plotAttributeProvider, curationTableModel); TraitInstanceCellRenderer tiCellRenderer = new TraitInstanceCellRenderer( curationData.getTraitColorProvider(), instanceNameProvider); traitInstanceCombo.setRenderer(tiCellRenderer); traitInstanceCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateActiveTraitInstance(); } }); traitInstanceCombo.getModel().addListDataListener(new ListDataListener() { @Override public void intervalRemoved(ListDataEvent e) { updateActiveTraitInstance(); } @Override public void intervalAdded(ListDataEvent e) { updateActiveTraitInstance(); } @Override public void contentsChanged(ListDataEvent e) { updateActiveTraitInstance(); } }); this.trial = curationData.getTrial(); this.plotCellChoicesPanel = pccp; for (TraitInstance t : curationData.getTraitInstances()) { String id = InstanceIdentifierUtil.getInstanceIdentifier(t); traitById.put(id, t); } // fieldViewSelectionModel = new FieldViewSelectionModel( // fieldLayoutTable, // fieldLayoutTableModel, // svs); fieldLayoutTable.setSelectionModel(fieldViewSelectionModel); plotCellRenderer.setCurationData(curationData); plotCellRenderer.setSelectionModel(fieldViewSelectionModel); plotCellChoicesPanel.addPlotCellChoicesListener(plotCellChoicesListener); fieldLayoutTableModel.setTrial(trial); // IMPORTANT: DO NOT SORT THE FIELD LAYOUT TABLE fieldLayoutTable.setAutoCreateRowSorter(false); JScrollPane fieldTableScrollPane = new JScrollPane(fieldLayoutTable); if (undockButton != null) { fieldTableScrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, undockButton); } fieldTableScrollPane.setRowHeaderView(rowHeaderTable); ChangeListener scrollBarChangeListener = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { fireRefreshRequired(); } }; fieldTableScrollPane.getVerticalScrollBar().getModel().addChangeListener(scrollBarChangeListener); fieldTableScrollPane.getHorizontalScrollBar().getModel().addChangeListener(scrollBarChangeListener); fieldLayoutTable.setRowHeaderTable(rowHeaderTable); // fieldLayoutTable.setComponentPopupMenu(popuMenu); initFieldLayoutTable(); Map<Integer, Plot> plotById = new HashMap<>(); FieldLayout<Integer> plotIdLayout = FieldLayoutUtil.createPlotIdLayout(trial.getTrialLayout(), trial.getPlotIdentSummary(), curationData.getPlots(), plotById); KdxploreFieldLayout<Plot> kdxFieldLayout = new KdxploreFieldLayout<Plot>(Plot.class, plotIdLayout.imageId, plotIdLayout.xsize, plotIdLayout.ysize); kdxFieldLayout.warning = plotIdLayout.warning; for (int y = 0; y < plotIdLayout.ysize; ++y) { for (int x = 0; x < plotIdLayout.xsize; ++x) { Integer id = plotIdLayout.cells[y][x]; if (id != null) { Plot plot = plotById.get(id); kdxFieldLayout.store_xy(plot, x, y); } } } fieldLayoutTableModel.setFieldLayout(kdxFieldLayout); if (kdxFieldLayout.warning != null && !kdxFieldLayout.warning.isEmpty()) { warningMessage.setText(kdxFieldLayout.warning); } else { warningMessage.setText(""); //$NON-NLS-1$ } changeVisitOrderAction.putValue(Action.SMALL_ICON, KDClientUtils.getIcon(kdxFieldLayout.imageId)); List<Component> components = new ArrayList<>(); components.add(alwaysOnTopOption); Collections.addAll(components, new JButton(changeVisitOrderAction), new JButton(curationHelpAction), traitInstanceCombo); Box resizeControls = KDClientUtils.createResizeControls(fieldLayoutTable, fontForResizeControls, components.toArray(new Component[components.size()])); resizeCombo = KDClientUtils.findResizeCombo(resizeControls); if (RunMode.getRunMode().isDeveloper()) { new FieldLayoutViewPanel.DebugSettings(resizeControls, messagePrinter); } JPanel fieldPanel = new JPanel(new BorderLayout()); // if (useSeparator) { // SeparatorPanel separator = GuiUtil.createLabelSeparator("Field Layout:", resizeControls); // fieldPanel.add(separator, BorderLayout.NORTH); // fieldPanel.add(fieldTableScrollPane, BorderLayout.CENTER); // } // else { fieldPanel.add(resizeControls, BorderLayout.NORTH); fieldPanel.add(fieldTableScrollPane, BorderLayout.CENTER); // } // splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, // plotCellChoicesPanel, // fieldPanel); // splitPane.setResizeWeight(0.0); // splitPane.setOneTouchExpandable(true); add(warningMessage, BorderLayout.NORTH); add(fieldPanel, BorderLayout.CENTER); // splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, // plotCellChoicesPanel, // fieldPanel); // splitPane.setResizeWeight(0.0); // splitPane.setOneTouchExpandable(true); // // add(warningMessage, BorderLayout.NORTH); // add(splitPane, BorderLayout.CENTER); fieldLayoutTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent me) { if (SwingUtilities.isRightMouseButton(me) && 1 == me.getClickCount()) { me.consume(); List<Plot> plots = getSelectedPlots(); List<TraitInstance> checkedInstances = new ArrayList<>(); for (int index = traitInstanceCombo.getItemCount(); --index >= 1;) { Object item = traitInstanceCombo.getItemAt(index); if (item instanceof TraitInstance) { checkedInstances.add((TraitInstance) item); } } TraitInstance ti = fieldViewSelectionModel.getActiveTraitInstance(true); List<PlotOrSpecimen> plotSpecimens = new ArrayList<>(); plotSpecimens.addAll(plots); curationMenuProvider.showFieldViewToolMenu(me, plotSpecimens, ti, checkedInstances); } } }); }
From source file:Main.java
public Main() { super("JScrollPane Demo"); JScrollPane scrollPane = new JScrollPane(label); JLabel[] corners = new JLabel[4]; for (int i = 0; i < 4; i++) { corners[i] = new JLabel(); corners[i].setBackground(Color.white); corners[i].setOpaque(true);// w w w. j a v a 2 s . co m } JLabel rowheader = new JLabel() { public void paintComponent(Graphics g) { super.paintComponent(g); Rectangle rect = g.getClipBounds(); for (int i = 50 - (rect.y % 50); i < rect.height; i += 50) { g.drawLine(0, rect.y + i, 3, rect.y + i); g.drawString("" + (rect.y + i), 6, rect.y + i + 3); } } public Dimension getPreferredSize() { return new Dimension(25, (int) label.getPreferredSize().getHeight()); } }; rowheader.setBackground(Color.white); rowheader.setOpaque(true); JLabel columnheader = new JLabel() { public void paintComponent(Graphics g) { super.paintComponent(g); Rectangle r = g.getClipBounds(); for (int i = 50 - (r.x % 50); i < r.width; i += 50) { g.drawLine(r.x + i, 0, r.x + i, 3); g.drawString("" + (r.x + i), r.x + i - 10, 16); } } public Dimension getPreferredSize() { return new Dimension((int) label.getPreferredSize().getWidth(), 25); } }; columnheader.setBackground(Color.white); columnheader.setOpaque(true); scrollPane.setRowHeaderView(rowheader); scrollPane.setColumnHeaderView(columnheader); scrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER, corners[0]); scrollPane.setCorner(JScrollPane.LOWER_RIGHT_CORNER, corners[1]); scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, corners[2]); scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, corners[3]); getContentPane().add(scrollPane); setSize(400, 300); setVisible(true); }
From source file:HeaderDemo.java
public HeaderDemo() { super("JScrollPane Demo"); JScrollPane scrollPane = new JScrollPane(label); JLabel[] corners = new JLabel[4]; for (int i = 0; i < 4; i++) { corners[i] = new JLabel(); corners[i].setBackground(Color.white); corners[i].setOpaque(true);/*from w ww .j a v a 2s .c om*/ } JLabel rowheader = new JLabel() { public void paintComponent(Graphics g) { super.paintComponent(g); Rectangle rect = g.getClipBounds(); for (int i = 50 - (rect.y % 50); i < rect.height; i += 50) { g.drawLine(0, rect.y + i, 3, rect.y + i); g.drawString("" + (rect.y + i), 6, rect.y + i + 3); } } public Dimension getPreferredSize() { return new Dimension(25, (int) label.getPreferredSize().getHeight()); } }; rowheader.setBackground(Color.white); rowheader.setOpaque(true); JLabel columnheader = new JLabel() { public void paintComponent(Graphics g) { super.paintComponent(g); Rectangle r = g.getClipBounds(); for (int i = 50 - (r.x % 50); i < r.width; i += 50) { g.drawLine(r.x + i, 0, r.x + i, 3); g.drawString("" + (r.x + i), r.x + i - 10, 16); } } public Dimension getPreferredSize() { return new Dimension((int) label.getPreferredSize().getWidth(), 25); } }; columnheader.setBackground(Color.white); columnheader.setOpaque(true); scrollPane.setRowHeaderView(rowheader); scrollPane.setColumnHeaderView(columnheader); scrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER, corners[0]); scrollPane.setCorner(JScrollPane.LOWER_RIGHT_CORNER, corners[1]); scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, corners[2]); scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, corners[3]); getContentPane().add(scrollPane); setSize(400, 300); setVisible(true); }