/* * This method is called every time: * - to make sure the viewport is returned to its default position * - to remove the horizontal scrollbar when it is not wanted */ private void checkHorizontalScrollBar(BasicComboPopup popup) { // Reset the viewport to the left JViewport viewport = scrollPane.getViewport(); Point p = viewport.getViewPosition(); p.x = 0; viewport.setViewPosition(p); // Remove the scrollbar so it is never painted if (!scrollBarRequired) { scrollPane.setHorizontalScrollBar(null); return; } // Make sure a horizontal scrollbar exists in the scrollpane JScrollBar horizontal = scrollPane.getHorizontalScrollBar(); if (horizontal == null) { horizontal = new JScrollBar(JScrollBar.HORIZONTAL); scrollPane.setHorizontalScrollBar(horizontal); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); } // Potentially increase height of scroll pane to display the scrollbar if (horizontalScrollBarWillBeVisible(popup, scrollPane)) { Dimension scrollPaneSize = scrollPane.getPreferredSize(); scrollPaneSize.height += horizontal.getPreferredSize().height; scrollPane.setPreferredSize(scrollPaneSize); scrollPane.setMaximumSize(scrollPaneSize); scrollPane.revalidate(); } }
public void scrollToAttribute(Attribute a) { if (!a.getDescriptor().getConfig().equals(getConfig())) { logger.fine("Cannot scroll to attribute that isn't attached to this type of descriptor"); return; } int rowIndex = getCurrentModel().getRowForDescriptor(a.getDescriptor()); int colIndex = getCurrentModel().getColumnForAttribute(a); JScrollPane scrollPane = (JScrollPane) this.getComponent(0); JViewport viewport = (JViewport) scrollPane.getViewport(); EnhancedTable table = (EnhancedTable) viewport.getView(); // This rectangle is relative to the table where the // northwest corner of cell (0,0) is always (0,0). Rectangle rect = table.getCellRect(rowIndex, colIndex, true); // The location of the viewport relative to the table Point pt = viewport.getViewPosition(); // Translate the cell location so that it is relative // to the view, assuming the northwest corner of the // view is (0,0) rect.setLocation(rect.x - pt.x, rect.y - pt.y); // Scroll the area into view viewport.scrollRectToVisible(rect); }
// // Implement the ChangeListener // public void stateChanged(ChangeEvent e) { // Keep the scrolling of the row table in sync with main table JViewport viewport = (JViewport) e.getSource(); JScrollPane scrollPane = (JScrollPane) viewport.getParent(); scrollPane.getVerticalScrollBar().setValue(viewport.getViewPosition().y); }
@Override public void addNotify() { super.addNotify(); Component c = getParent(); // Keep scrolling of the row table in sync with the main table. if (c instanceof JViewport) { JViewport viewport = (JViewport) c; viewport.addChangeListener(this); } }
public HtmlPane() { try { URL url = getClass().getResource("/resources/HelpFiles/toc.html"); html = new JEditorPane(url); html.setEditable(false); html.addHyperlinkListener(this); html.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); JViewport vp = getViewport(); vp.add(html); } catch (MalformedURLException e) { System.out.println("Malformed URL: " + e); } catch (IOException e) { System.out.println("IOException: " + e); } }
@SuppressWarnings("OverridableMethodCallInConstructor") Notepad() { super(true); // Trying to set Nimbus look and feel try { for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (Exception ignored) { } setBorder(BorderFactory.createEtchedBorder()); setLayout(new BorderLayout()); // create the embedded JTextComponent editor = createEditor(); // Add this as a listener for undoable edits. editor.getDocument().addUndoableEditListener(undoHandler); // install the command table commands = new HashMap<Object, Action>(); Action[] actions = getActions(); for (Action a : actions) { commands.put(a.getValue(Action.NAME), a); } JScrollPane scroller = new JScrollPane(); JViewport port = scroller.getViewport(); port.add(editor); String vpFlag = getProperty("ViewportBackingStore"); if (vpFlag != null) { Boolean bs = Boolean.valueOf(vpFlag); port.setScrollMode(bs ? JViewport.BACKINGSTORE_SCROLL_MODE : JViewport.BLIT_SCROLL_MODE); } JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.add("North", createToolbar()); panel.add("Center", scroller); add("Center", panel); add("South", createStatusbar()); }
public HtmlPane(String helpFileName) { try { File f = new File(helpFileName); String s = f.getAbsolutePath(); s = "file:" + s; URL url = new URL(s); html = new JEditorPane(s); html.setEditable(false); html.addHyperlinkListener(this); JViewport vp = getViewport(); vp.add(html); } catch (MalformedURLException e) { System.out.println("Malformed URL: " + e); } catch (IOException e) { System.out.println("IOException: " + e); } }
public void actionPerformed(ActionEvent e) { PrintJob pjob = getToolkit().getPrintJob(textViewerFrame, "Printing Nslm", null); if (pjob != null) { Graphics pg = pjob.getGraphics(); if (pg != null) { // todo: this should print from // the file not from the screen. // if (editor1!=null) { // editor1.print(pg); //print crashes, must use printAll // } // if (scroller1!=null) { // scroller1.printAll(pg); //is clipping on left // } if (scroller1 != null) { JViewport jvp = scroller1.getViewport(); jvp.printAll(pg); } pg.dispose(); } pjob.end(); } }