Re: Custom JScrollPane - Double JScrollBars
You'll have to override the layout manager.
In the example below, I made the scroll pane display 2 vertical bars.
All I did was resize/reposition the viewport, the vertical and the
horizontal bar.
The outer most vertical bar will still act like that standard horiz
bar.
The inner vertical bar will be the same normal vertical bar.
PS.
Are you sure you really need to do this?
I agree with RGB that you sure have a look at the other default panes
just make sure. =/
---------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class MySPLayout extends ScrollPaneLayout
{
public void layoutContainer(Container parent)
{
hsb.setOrientation(JScrollBar.HORIZONTAL);
super.layoutContainer(parent);
Rectangle hRec = hsb.getBounds();
Rectangle vRec = vsb.getBounds();
Dimension size = viewport.getExtentSize();
// adjust viewport size, add to the bottom, sub from right side
size.width -= vRec.width;
size.height += hRec.height;
viewport.setExtentSize(size);
// get rid of the corner
vRec.height += hRec.height;
// scoot over to make room
vsb.setLocation(vRec.x - vRec.width, vRec.y);
vsb.setSize(vRec.width, vRec.height);
hsb.setOrientation(JScrollBar.VERTICAL);
hsb.setLocation(vRec.x, vRec.y);
hsb.setSize(vRec.width, vRec.height);
}
}
public class GUI extends JFrame /* implements ActionListener */
{
// GUI objects
JTextArea m_pText;
JScrollPane m_pScrollPane;
GUI()
{
super("Test GUI");
m_pText = new JTextArea("This is a test.");
m_pText.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
m_pScrollPane = new JScrollPane(m_pText);
m_pScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
m_pScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
m_pScrollPane.setLayout(new MySPLayout());
add(m_pScrollPane);
pack();
}
public void dispose()
{
super.dispose();
}
}