/** * Sets the view for this scroll pane. This must be an {@link RTextArea}. * * @param view The new view. * @see #getTextArea() */ @Override public void setViewportView(Component view) { RTextArea rtaCandidate = null; if (!(view instanceof RTextArea)) { rtaCandidate = getFirstRTextAreaDescendant(view); if (rtaCandidate==null) { throw new IllegalArgumentException( "view must be either an RTextArea or a JLayer wrapping one"); } } else { rtaCandidate = (RTextArea)view; } super.setViewportView(view); if (gutter!=null) { gutter.setTextArea(rtaCandidate); } }
/** * Creates a scroll pane. * * @param comp The component this scroll pane should display. This should * be an instance of {@link RTextArea}, * <code>javax.swing.JLayer</code> (or the older * <code>org.jdesktop.jxlayer.JXLayer</code>), or <code>null</code>. * If this argument is <code>null</code>, you must call * {@link #setViewportView(Component)}, passing in an instance of * one of the types above. * @param lineNumbers Whether line numbers are initially enabled. * @param lineNumberColor The color to use for line numbers. */ public RTextScrollPane(Component comp, boolean lineNumbers, Color lineNumberColor) { super(comp); RTextArea textArea = getFirstRTextAreaDescendant(comp); // Create the gutter for this document. Font defaultFont = new Font("Monospaced", Font.PLAIN, 12); gutter = new Gutter(textArea); gutter.setLineNumberFont(defaultFont); gutter.setLineNumberColor(lineNumberColor); setLineNumbersEnabled(lineNumbers); // Set miscellaneous properties. setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_ALWAYS); setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_AS_NEEDED); }
/** * Sets the view for this scroll pane. This must be an {@link RTextArea}. * * @param view The new view. * @see #getTextArea() */ @Override public void setViewportView(Component view) { RTextArea rtaCandidate = null; if (!(view instanceof RTextArea)) { rtaCandidate = getFirstRTextAreaDescendant(view); if (rtaCandidate==null) { throw new IllegalArgumentException( "view must be either an RTextArea or a JLayer wrapping one"); } } else { rtaCandidate = (RTextArea)view; } super.setViewportView(view); if (gutter!=null) { gutter.setTextArea(rtaCandidate); } }
/** * Creates a scroll pane. * * @param comp The component this scroll pane should display. This should * be an instance of {@link RTextArea}, * <code>javax.swing.JLayer</code> (or the older * <code>org.jdesktop.jxlayer.JXLayer</code>), or <code>null</code>. * If this argument is <code>null</code>, you must call * {@link #setViewportView(Component)}, passing in an instance of * one of the types above. * @param lineNumbers Whether line numbers are initially enabled. * @param lineNumberColor The color to use for line numbers. */ public RTextScrollPane(Component comp, boolean lineNumbers, Color lineNumberColor) { super(comp); RTextArea textArea = getFirstRTextAreaDescendant(comp); // Create the gutter for this document. Font defaultFont = new Font("Monospaced", Font.PLAIN, 12); gutter = new Gutter(textArea); gutter.setLineNumberFont(defaultFont); gutter.setLineNumberColor(lineNumberColor); setLineNumbersEnabled(lineNumbers); // Set miscellaneous properties. setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_ALWAYS); setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_AS_NEEDED); }