0

I'm trying to create a text editor, so I've created a JTextArea that expands into a JScrollPane.

I'm running Windows 10 and java version "1.6.0_38"

I am fairly new to javax.swing (I've only learned AWT so far), the trackpad seems to work when I tried going back to the older java.awt.TextArea.

public class CustomFrame extends JFrame {
    public CustomFrame() {
        this.setBackground(new Color(255, 255, 255));   
        this.setEditor();
        this.pack();
    }
    private void setEditor() {
        this.setTitle("Text Editor");
        JTextArea text = new JTextArea("");
        JScrollPane sp = new JScrollPane(text, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        this.getContentPane().add(sp);
        this.setVisible(true);
    }
}

In the javax.swing.JScrollPane the trackpad isn't detected by the app, and scrolls the Command Line window in the background instead.

Turismo98
  • 149
  • 1
  • 1
  • 13
  • 1
    What OS? What version of the OS? What version of Java? – MadProgrammer Apr 04 '19 at 23:34
  • My bad, I've updated the OP to include the OS and Java version – Turismo98 Apr 04 '19 at 23:37
  • 1) For better help sooner, [edit] to add a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) Prefill the text area with enough text to make it **need** scrolling. Specifying rows and columns would also help. 3) `this.setBounds(x, y, width, height);` That's just a guess. Always `pack()` a GUI, after all components are added for it to end up the size it needs to be. 4) No need to extend `JFrame`, just use a standard instance. 5) `this.getContentPane().setLayout(new BorderLayout());` Border layout is the default for a frame! – Andrew Thompson Apr 05 '19 at 04:11
  • BTW - the code specifies a permanent vertical scroll-bar and no horizontal scroll-bar. Given the text area was not set to line wrap, the text just continues on (the same line) out the sides of the scroll pane. Hence a scroll wheel will have no effect. – Andrew Thompson Apr 05 '19 at 04:21
  • 1
    I guess you are looking for [this](https://stackoverflow.com/questions/8256888/java-trackpad-2-finger-scroll-listener). – Maifee Ul Asad Apr 05 '19 at 18:02
  • I tried but the MouseWheelListener wasn't triggered by the trackpad scroll. – Turismo98 Apr 09 '19 at 23:39
  • I guess it's a problem with JTextArea doing it's own scrolling, and thereby eating the relevant events. It may be more appropriate to use other text components for anything non-trivial. I don't have time to check at the moment. – Tom Hawtin - tackline Jul 21 '20 at 17:37

0 Answers0