Make JScrollPane control multiple components

You should use JScrollPane#setRowHeaderView to set the component that will appear at the left hand side of the scroll pane. The benefit of this is the row header won’t scroll to the left as the view scrolls to the right… The example deliberately uses line wrapping… import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.FontMetrics; import … Read more

Java / Swing : JTextArea in a JScrollPane, how to prevent auto-scroll?

How to set AUTO-SCROLLING of JTextArea in Java GUI? http://download.oracle.com/javase/1.5.0/docs/api/javax/swing/text/DefaultCaret.html#NEVER_UPDATE Try: JTextArea textArea = new JTextArea(); DefaultCaret caret = (DefaultCaret)textArea.getCaret(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); This should prevent the caret from automatically making the document scroll to the bottom.

jTextArea as IO console

Okay, so this is my idea… The basic idea is we want to keep track of “user” input and “process” output. Basically what I’ve done is set it up so that when the process terminates, we calculate the current position of the caret in the document and mark that as the start position of the … Read more

ActionListener for a specific text inside a JTextArea?

Here try this small program, try to click at the start of student://, that will pop up a message Dialog import java.awt.*; import java.awt.event.*; import javax.swing.*; public class TextAreaExample extends JFrame { private JTextArea tarea = new JTextArea(10, 10); private JTextField tfield = new JTextField(10); private void createAndDisplayGUI() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); tarea.setText(“Hello there\n”); tarea.append(“Hello student://”); JScrollPane … Read more

How to change highlighting color in Java Swing TextArea? And also, change the beginning of text corresponding to the highlighting location

You can achieve this, though not directly, since you have to save the reference to the Highlight that you had added to the said line, hence you have to traverse through all the Highlights to remove the one you want, have a look at the program attached, might be this will help you to attain … Read more

Internal padding for JTextArea with background Image

Use a custom border that extends AbstractBorder. Something like this: Getting the exact shape & color is left as an exercise for the reader. 🙂 import java.awt.*; import java.awt.geom.*; import javax.swing.*; import javax.swing.border.AbstractBorder; class TextBubbleBorder extends AbstractBorder { private Color color; private int thickness = 4; private int radii = 8; private int pointerSize = … Read more

How to set the orientation of JTextArea from right to left (inside JOptionPane)

and the scrollbar will be on the left scrollPane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); so the text inside it will start from the right textArea.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); The text starts on the right side, but still gets append to the end as you type instead of being inserted at the beginning of the line. Update: I don’t know why it doesn’t work … Read more

Java – Scroll to specific text inside JTextArea

This is a VERY basic example. This basically walks the document to find the position of the word within the document and ensures that the text is moved to the viewable area. It also highlights the match public class MoveToText { public static void main(String[] args) { new MoveToText(); } public MoveToText() { EventQueue.invokeLater(new Runnable() … Read more

tech