/** * 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); }
private void checkBoxActionPerformed(ActionEvent evt) { if(checkBox.isSelected()) { textArea.setLineWrap(true); sp.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); callbacks.saveExtensionSetting("wrapLinesInSourceViewer", "true"); } else { textArea.setLineWrap(false); sp.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); callbacks.saveExtensionSetting("wrapLinesInSourceViewer", "false"); } }
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); }); }
sp.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); checkBox = new JCheckBox("Softwraps for long lines"); checkBox.setSelected(false);
/** * 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); }