Solved

multiple scrollpanes

Posted on 1998-08-10
6
238 Views
Last Modified: 2012-08-13

I have a table (Im not using swing...even though maybe I should be) that i need to be able to scroll.
I would like to have the heading of the table stay in one place and have the data underneath it scroll vertically.
On low resolution systems I also need the whole thing (including the heading) scroll horizontally.
Obviously the headings have to stay above the data that is associated with it
Ive played around with this using two ScrollPanes one for the top and one for the data
The code should help to show you want I mean (I may not have explained it too well):

this.setLayout(new BorderLayout(10,10));
this.setBackground(Color.lightGray);
Panel head= new Panel();
head.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
this.add("North",head);
head.setFont(new Font("SansSerif",Font.BOLD,20));
currRay=(String[]) vect.elementAt(0);
head.add(new Label(currRay[0]));
Panel buttons= new Panel();
buttons.setLayout(new FlowLayout(FlowLayout.CENTER,30,10));
this.add("South",buttons);
linegraph=new Button("View LineGraph");
bargraph= new Button("View BarGraph");
piegraph= new Button("View PieGraph");
cancel= new Button("Cancel");
cancel.addActionListener(new ActionListener()  {
     public void actionPerformed(ActionEvent e)  {
          System.exit(0);
     }
});
buttons.add(linegraph);
buttons.add(bargraph);
buttons.add(piegraph);
buttons.add(cancel);
Panel headbody= new Panel();
headbody.setLayout(new GridLayout(0,10,10,10));
for (int i=0;i<10;i++)  {
     headbody.add(new Label("Label " + i));
}
Panel databody= new Panel();
databody.setLayout(new GridLayout(10,0,10,10));
for (int i=0;i<10;i++)  {
     for (int j=0;j<10;j++)  {
      databody.add(new Label("Data[" + i + "][" + j + "]"));
     }
}
ScrollPane scrolldata= new ScrollPane();
scrolldata.add(databody);
Panel body= new Panel();
body.setLayout(new BorderLayout(0,0));
body.setBackground(Color.white);
body.add("North",headbody);
body.add("Center",scrolldata);
ScrollPane scrollbody= new ScrollPane();
scrollbody.add(body);
this.add("Center",scrollbody);

At least thats the basic idea behind it.  This code only scrolls the outer scrollpane. You can see the inner scrollpane but there is no scrolling involved.  Ive messed around with various changes to this code but this is about the closest ive come
Normally I try to bang away on things until I get it to work but in this case Im not even sure it is possible (or should be) I will also accept other ways to do the same type of thing (I cant use swing for the time being though)

Any help would be greatly appreciated
Thanks
0
Comment
Question by:conick
  • 4
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
mjenkins earned 70 total points
Comment Utility
Firstly, I would strongly recommend using the Swing JTable. It addresses all of your needs (as described) with no additional programming on your part. If you cannot use swing, there are several commercial table components that you can purchase which will, again, address all of your issues without additional programming. If this is not acceptable, then you CAN accomplish what you describe with just the existing AWT.

I had to do just this before swing came out (JDK 1.0.x - JDK 1.1.2). THe approach that I used was to create what was effectively 2 tables embeded in a borderlayout in a parent panel. The "North" table was strictly for the headers. The "Center" table was for the data. Anytime the Center table was scrolled horizontally, I would propagate the scrolling to the North table thereby realigning the "Headers" with the "Data". Vertical scrolling was ignored by the North table ( and VERTICAL scrollbars were disallowed in the header area altogether).

0
 
LVL 7

Author Comment

by:conick
Comment Utility

You say to disallow vertical scrollbars in the header, however, there are only three display policies (always,as_needed,never) how do i allow one and not the other (if the component thinks it is needed)




0
 
LVL 7

Author Comment

by:conick
Comment Utility

Does JRE 1.1.6 support SWING without any further downloads?
If thats the case then I CAN use SWING
(which would be great)

0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 7

Author Comment

by:conick
Comment Utility
Last one, promise:
what version of swing do i download?
SWING 1.0 or SWING 1.1 Beta

I am using JRE 1.1.6 and whatever SWING version i use needs to be compatible with
that

Sorry for all these questions.. ill up the points a bit
0
 
LVL 3

Expert Comment

by:mjenkins
Comment Utility
First Comment:
I'm sorry, I meant to say "disallow scrollbars in the headers" not just VERTICAL scrollbars. You are of course, right that in awt you can't distinguish in the ScrollPane. The Header doesn't need any scrollbars because all of it's scrolling behavior is from the other scrollpane (the data table).

Second comment:
You do need to download the swing components themselves. But beyond that, they work right with the JRE 1.1.6 out of the box. They really do simplify the UI development quite a bit. You will find that you REALLY need a JIT, however (standard on the Windows JRE).

Third Comment:
I would use Swing 1.0 for the time being. Knowing Sun, there will most likely be a 1.1.1 shortly to fix the bugs in 1.1... We've been using 1.0.2 successfully for some time now.

Final note: After you download the swing set, run through the examples for the JTable. They show off many of the capabilities of the standard component...things like the built in column reordering.
0
 
LVL 7

Author Comment

by:conick
Comment Utility

ahhh I think im gonna have to bite the bullet and learn swing.
Ive been meaning to but I just wanted to get this one project done first
now i have something to work with it on

Youve been more than helpful
Thanks mjenkins


0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Updating Java 9 86
Free Alternative to JIRA 4 51
@SBGen Method 3 25
Java - Why doesn't this JFrame work 3 14
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now