Solved

multiple scrollpanes

Posted on 1998-08-10
6
244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

729 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