Java Utililty Methods JScrollPane

List of utility methods to do JScrollPane

Description

The list of methods to do JScrollPane are organized into topic(s).

Method

JScrollPanefindScrollPane(Component component)
find Scroll Pane
if (component instanceof JScrollPane)
    return (JScrollPane) component;
if (component instanceof Container) {
    Container c = (Container) component;
    for (int i = 0; i < c.getComponentCount(); i++) {
        JScrollPane result = findScrollPane(c.getComponent(i));
        if (result != null)
            return result;
...
JScrollPanegetContainingScroll(Component comp)
Returns the scrolpane where the provided component is contained.
JScrollPane scroll = null;
Container parent = comp.getParent();
while (scroll == null && parent != null) {
    if (parent instanceof JScrollPane) {
        scroll = (JScrollPane) parent;
    } else {
        parent = parent.getParent();
return scroll;
JScrollPanegetMessageScrollPane(String message)
get Message Scroll Pane
JTextArea ta = new JTextArea(message);
ta.setBorder(new EmptyBorder(0, 0, 0, 0));
ta.setLineWrap(true);
ta.setWrapStyleWord(true);
ta.setCaretPosition(0);
ta.setEditable(false);
JScrollPane sp = new JScrollPane(ta);
sp.setBorder(new EmptyBorder(5, 5, 5, 5));
...
JFramegetNoScrollPaletteWindow(Component gui, String windowName, ComponentListener cl)
Get a layer's associated palette as a top-level window
JPanel pane = new JPanel();
pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
pane.setAlignmentX(Component.CENTER_ALIGNMENT);
pane.setAlignmentY(Component.BOTTOM_ALIGNMENT);
pane.add(gui);
JFrame paletteWindow = new JFrame(windowName);
paletteWindow.addComponentListener(cl);
paletteWindow.getContentPane().add(pane);
...
JScrollPanegetScrollableMessage(String msg)
get Scrollable Message
JTextArea textArea = new JTextArea(msg);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.setEditable(false);
textArea.setMargin(new Insets(5, 5, 5, 5));
textArea.setFont(new JTextField().getFont()); 
JScrollPane scrollPane = new JScrollPane();
scrollPane.setPreferredSize(new Dimension(700, 150));
...
intgetScrollBarWidth(BasicComboPopup popup, JScrollPane scrollPane)
get Scroll Bar Width
return 0;
RectanglegetScrollPaneViewportSize(JScrollPane panel)
get Scroll Pane Viewport Size
Rectangle viewRect = panel.getViewportBorderBounds();
JScrollBar vbar = panel.getVerticalScrollBar();
if (vbar.isVisible()) {
    viewRect.width = viewRect.width + vbar.getWidth();
JScrollBar hbar = panel.getHorizontalScrollBar();
if (hbar.isVisible()) {
    viewRect.height = viewRect.height + hbar.getHeight();
...
booleanhasParentScrollPane(JComponent component)
has Parent Scroll Pane
return component.getParent() != null && component.getParent() instanceof JViewport
        && component.getParent().getParent() instanceof JScrollPane;
GridBagConstraintsinitScrollPane(JScrollPane scrollPane)
init Scroll Pane
scrollPane.setLayout(new ScrollPaneLayout());
scrollPane.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
GridBagConstraints gb = new GridBagConstraints();
gb.gridx = 0;
gb.gridy = 0;
gb.insets = new Insets(2, 2, 2, 2);
return gb;
booleanisHorizontalScrollBarHiddenAlways(JScrollPane pane)
is Horizontal Scroll Bar Hidden Always
return (pane != null) && (pane.getHorizontalScrollBarPolicy() == JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);