Re: Scroll bar not showing up
fiziwig schrieb:
Andrew Thompson wrote:
fiziwig wrote:
Andrew Thompson wrote:
...
I took my scrollbar code from
http://www.java2s.com/Code/Java/Swing-JFC/AquickdemonstrationofJScrollBarbothverticalandhorizontal.htm
which supposedly works.
...
...there are no mention of JLayeredPane's in that example.
In the end I changed your JLayeredPane for a JPanel and the
JScrollBar appeared.
Then I guess my question boils down to how do I make a scrollbar appear
in a JLayered Pane?
FWIW: I changed my JLayeredPane to a JPanel and the scroll bars did
show up, BUT the rest of the application is totally broken by that
change. :-(
--gary
Hi!
Perhaps that little example can help you. I think your problem is, that
you cannot show ANY components on the JLayeredPane, you even were not
able to show a JButton...
I can imagine, the problem is the LayoutManager. Perhaps JLayeredPane is
not compatible with all LayoutManagers. I don't know - sorry.
But in fact, it does work with FlowLayout. In my diploma-thesis I have
to use it with a null-Layout and that works fine, too.
import javax.swing.*;
import java.awt.*;
public class JLayeredPaneTest extends JFrame {
JLayeredPane layeredPane;
public JLayeredPaneTest() {
super("Example");
setDefaultCloseOperation(EXIT_ON_CLOSE);
layeredPane = new JLayeredPane();
layeredPane.setLayout(new FlowLayout());
JScrollBar vScrollBar = new JScrollBar(JScrollBar.VERTICAL);
JButton button = new JButton("Button");
layeredPane.add(vScrollBar);
layeredPane.add(button);
layeredPane.setPreferredSize(new Dimension(200,200));
setContentPane(layeredPane);
}
public static void main(String[] args) {
JLayeredPaneTest test = new JLayeredPaneTest();
test.pack();
test.setVisible(true);
}
}
Hope that helps!
bye, Ralf