Solved

multiple scrollpanes

Posted on 1998-08-10
6
242 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
ID: 1232260
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
ID: 1232261

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
ID: 1232262

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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 7

Author Comment

by:conick
ID: 1232263
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
ID: 1232264
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
ID: 1232265

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
factorial example 4 47
fibonacci ten numbers 4 45
Opening PDF on button click and fill new document 2 47
jsp error 6 25
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

856 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