Results 1 to 6 of 6
- 07-11-2011, 08:03 AM #1
Member
- Join Date
- Jul 2011
- Posts
- 3
- Rep Power
- 0
Scrolling while producing components dynamically
I hava a JPanel.
I have a JButton in the JPanel. While this JButton is pressed, a lot of other components apear on the JPanel. The JButton can be pressed several times. So, there are lots of components on the JPanel.
So, JPanel should be scrolled. I put the JPanel inside a JScrollPanell, but it didn't work.
Can anybody help me please?
- 07-11-2011, 09:09 AM #2
Hmm, well here is a tutorial on ScrollPanes. You might find some useful info here.
How to Use Scroll Panes (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
Ive never really messed with scrolling JPanels, but after consulting google the general consensus is that there are a couple of ways to do it. This link on Stack Overflow has suggestions from using a viewport to setting your JPanel preferred size to larger than your frame preferred size and adding the JPanel to a ScrollPane.
java - Scrollable JPanel - Stack Overflow
If that's not what you're looking for then have a looksy at these links.
Java Answers Forum - How to make JPanel scrollable?
JPanel with scroll bar - DevX.com Forums
How to Use Scroll Panes (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
Java Swing:Scrollable JPanel
Sorry I couldn't help you more, but hopefully these people have had similar problems with working solutions that you can learn from.- Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
- +Rep people for helpful posts.
- 07-11-2011, 05:48 PM #3
Member
- Join Date
- Jul 2011
- Posts
- 3
- Rep Power
- 0
thanX Dark,
I had seen the first link you introduced and it didn't work.
I don't want to scrollize(my word) the JPanel, I don't want to produce something, I just want a solution to let me continue my work, because I have a lot to do and not much time.
I tried all the relevant methods of JscrollPane, but none of them worked, I don't know whether there's no capability in Java for this problem, or I'm doing something wrong.
- 07-11-2011, 06:08 PM #4
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
You are doing something wrong.or I'm doing something wrong
And you haven't provided us with enough infomation to help. We also dont' have time to spend guessing what you might be doing.I have a lot to do and not much time.
The basic code for creating a scroll pane is:
If you dynamically add components then the basic code is:Java Code:JPanel panel = new JPanel(); panel.add(...); JScrollPane scrollPane = new JScrollPane( panel ); frame.add( scrollPane );
If you need more help then post your Short, Self Contained, Correct Example.Java Code:panel.add( anotherComponent ); panel.revalidate(); panel.repaint();
- 07-11-2011, 06:48 PM #5
Member
- Join Date
- Jul 2011
- Posts
- 3
- Rep Power
- 0
Dear friend,
to be complete, the hierarchy of my containers is as follows: JTabbedPane->JScrollPane->JPanel
I have a JButton inside the JPanel.
Each time the JButton is pressed, a line of components is dynamically generated: JLabel, JTextField, JLabel, JTextField, JButton
So, with multiple pressing the button, lots of these lines are generated vertically.
The problem is that when the components exceed the current view of the JPanel, the scrollbars don't work, even when the scrollbar policy is set to ALWAYS.
I hope that I was clear, complete and concise
- 07-11-2011, 07:09 PM #6
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Similar Threads
-
Producing Congruent Numbers
By freddy92 in forum New To JavaReplies: 2Last Post: 07-04-2011, 01:54 PM -
Help - special characters producing 404 errors
By Knedlikova in forum New To JavaReplies: 3Last Post: 11-17-2010, 09:13 AM -
Why is this producing ArrayIndexOutOfBoundsException?
By BentByBogus in forum New To JavaReplies: 5Last Post: 10-08-2010, 09:32 PM -
Problem producing XML
By ashleyh in forum Java ServletReplies: 0Last Post: 04-13-2008, 04:29 PM -
producing DOCs
By javaplus in forum New To JavaReplies: 0Last Post: 11-18-2007, 06:08 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks