Results 1 to 6 of 6
  1. #1
    ijustloveit13 is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Exclamation 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?

  2. #2
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    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.

  3. #3
    ijustloveit13 is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default

    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.

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    or I'm doing something wrong
    You are doing something wrong.

    I have a lot to do and not much time.
    And you haven't provided us with enough infomation to help. We also dont' have time to spend guessing what you might be doing.

    The basic code for creating a scroll pane is:

    Java Code:
    JPanel panel = new JPanel();
    panel.add(...);
    JScrollPane scrollPane = new JScrollPane( panel );
    frame.add( scrollPane );
    If you dynamically add components then the basic code is:

    Java Code:
    panel.add( anotherComponent );
    panel.revalidate();
    panel.repaint();
    If you need more help then post your Short, Self Contained, Correct Example.

  5. #5
    ijustloveit13 is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default

    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

  6. #6
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    I hope that I was clear, complete and concise
    It doesn't change my answer. Try my suggestions and post your SSCCE if it still doesn't work.

Similar Threads

  1. Producing Congruent Numbers
    By freddy92 in forum New To Java
    Replies: 2
    Last Post: 07-04-2011, 02:54 PM
  2. Help - special characters producing 404 errors
    By Knedlikova in forum New To Java
    Replies: 3
    Last Post: 11-17-2010, 10:13 AM
  3. Why is this producing ArrayIndexOutOfBoundsException?
    By BentByBogus in forum New To Java
    Replies: 5
    Last Post: 10-08-2010, 10:32 PM
  4. Problem producing XML
    By ashleyh in forum Java Servlet
    Replies: 0
    Last Post: 04-13-2008, 05:29 PM
  5. producing DOCs
    By javaplus in forum New To Java
    Replies: 0
    Last Post: 11-18-2007, 07:08 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •