Solved

multiple scrollpanes

Posted on 1998-08-10
6
241 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
GUI builder for Eclipse? 8 35
web services creation SOAP vs REST 5 41
table example 4 29
Which non-HTML GUI front end to use with Java? 3 22
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

773 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