?
Solved

multiple scrollpanes

Posted on 1998-08-10
6
Medium Priority
?
245 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 280 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Industry Leaders: 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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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 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 …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 23 hours left to enroll

752 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