scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); final JScrollBar verticalScrollbar = scrollPane.getVerticalScrollBar(); if (verticalScrollbar != null) {
/** * 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); }
public static void main(String args[]) { SwingUtilities.invokeLater(() -> { WebLookAndFeel.install(); JFrame frame = new JFrame("Teste Editor"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(800, 600); JPanel painel = new JPanel(new BorderLayout()); Editor editor = new Editor(); editor.scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); editor.scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); StringBuilder builder = new StringBuilder(); for (int i = 0; i < 60; i++) { builder.append("linha ").append(String.valueOf(i)).append("\n"); } editor.setCodigoFonte(builder.toString()); painel.add(editor); WeblafUtils.configuraWeblaf(painel); frame.getContentPane().add(painel, BorderLayout.CENTER); frame.setVisible(true); }); }
/** * Creates a scroll pane with preferred size (width, height). * * @param area The text area this scroll pane will contain. If this is * <code>null</code>, you must call * {@link #setViewportView(Component)}, passing in an * {@link RTextArea}. * @param lineNumbers Whether line numbers are initially enabled. * @param lineNumberColor The color to use for line numbers. */ public RTextScrollPane(RTextArea area, boolean lineNumbers, Color lineNumberColor) { super(area); // Create the text area and set it inside this scroll bar area. textArea = area; // 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); }
/** * Creates a scroll pane with preferred size (width, height). * * @param area The text area this scroll pane will contain. If this is * <code>null</code>, you must call * {@link #setViewportView(Component)}, passing in an * {@link RTextArea}. * @param lineNumbers Whether line numbers are initially enabled. * @param lineNumberColor The color to use for line numbers. */ public RTextScrollPane(RTextArea area, boolean lineNumbers, Color lineNumberColor) { super(area); // Create the text area and set it inside this scroll bar area. textArea = area; // 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); }
/** * 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); }
@SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { scrollPane = new org.fife.ui.rtextarea.RTextScrollPane(); textArea = new PSTextArea(new PortugolDocumento()); setOpaque(false); setLayout(new java.awt.BorderLayout()); scrollPane.setBorder(null); scrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); scrollPane.setViewportBorder(javax.swing.BorderFactory.createEmptyBorder(3, 5, 0, 0)); scrollPane.setName("scrollPaneEditor"); // NOI18N scrollPane.setOpaque(false); textArea.setBorder(null); textArea.setToolTipText(""); textArea.setCodeFoldingEnabled(true); textArea.setName("textAreaEditor"); // NOI18N scrollPane.setViewportView(textArea); add(scrollPane, java.awt.BorderLayout.CENTER); }// </editor-fold>//GEN-END:initComponents