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.

Java Swing : why must resize frame, so that can show components have added

Do not add components to JFrame after the JFrame is visible (setVisible(true)) Not really good practice to call setSize() on frame rather call pack() (Causes JFrame to be sized to fit the preferred size and layouts of its subcomponents) and let LayoutManager handle the size. Use EDT (Event-Dispatch-Thread) call JFrame#setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) as said by @Gilbert Le … Read more

How to make JScrollPane (In BorderLayout, containing JPanel) smoothly autoscroll

You can set the value of the horizontal scrollbar to control what is currently visible: JScrollBar horizontal = scroll.getHorizontalScrollBar(); horizontal.setValue( horizontal.getValue() + ??? ); You would need to use a Swing Timer to schedule the scrolling at an appropriate interval. Simple example of using a Timer to scroll text: import java.awt.*; import java.awt.event.*; import java.util.*; … Read more

JTable with horizontal scrollbar

First, add your JTable inside a JScrollPane and set the policy for the existence of scrollbars: new JScrollPane(myTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); Then, indicate that your JTable must not auto-resize the columns by setting the AUTO_RESIZE_OFF mode: myJTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

How to set AUTO-SCROLLING of JTextArea in Java GUI?

When using JDK1.4.2 (or earlier) the most common suggestion you will find in the forums is to use code like the following: textArea.append(…); textArea.setCaretPosition(textArea.getDocument().getLength()); However, I have just noticed that in JDK5 this issue has actually been resolved by an API change. You can now control this behaviour by setting a property on the DefaultCaret … Read more

Why JScrollPane in JOptionPane not showing all its content?

As shown in this related example, you can override the viewport’s preferred size. import java.awt.Dimension; import java.awt.EventQueue; import javax.swing.GroupLayout; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.SwingConstants; /** * @see https://stackoverflow.com/a/14858272/230513 * @see https://stackoverflow.com/a/8504753/230513 * @see https://stackoverflow.com/a/14011536/230513 */ public class DynamicGroupLayout { private static final int NUM = 30; private JTextField[] … Read more

Java – Transparent JScrollPane

You need to use setOpaque(false) to make it transparent. Call that both on the JScrollPane, and on it’s ViewPort. sp.setOpaque(false); sp.getViewport().setOpaque(false); You’ll also have to call setOpaque(false) on the JTextArea, if you want that transparent as well.

Resizing issue with canvas within jscrollpane within jsplitpane

Instead of setPreferredSize(), let your components calculate their own preferred size and pack() the enclosing Window to accommodate. The example below adds an instance of draw.GraphPanel to the top and a corresponding control panel to the bottom. import draw.GraphPanel; import java.awt.EventQueue; import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSplitPane; /** * @see https://stackoverflow.com/q/11942961/230513 … Read more