aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes ScrollPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ScrollPane" Watch "ScrollPane" New topic
Author

ScrollPane

Philip Pross
Ranch Hand

Joined: Jan 17, 2001
Posts: 76
Hello there,
I'm having a problem with my applet, basicallyI have too many components in my window so I wanted scrolls. After doing a test on the side if I use one label, it works. But with two it only add the adds the last component .....heres the test that works

import java.lang.*;
import java.awt.*;
import java.applet.*;
public class ScrollPaneSample extends Applet
{
Dimension dimScreenSize;
Frame frame;
ScrollPane scrollPane;
Label label;
int frameX, frameY, frameWidth, frameHeight;
public void init()
{
setLayout(null);
dimScreenSize = Toolkit.getDefaultToolkit().getScreenSize();
frameWidth = 256;
frameHeight = 160;
frameX = (dimScreenSize.width - frameWidth) / 2;
frameY = (dimScreenSize.height - frameHeight) / 2;
frame = new Frame("Search");
scrollPane = new ScrollPane();
label = new Label("Label");
label.setFont(new Font("Serif", Font.PLAIN, 128) );

scrollPane.add(label);
frame.add(scrollPane);
frame.setSize(frameWidth,frameHeight);
frame.setLocation(frameX, frameY);
frame.setVisible(true);
}
}
Like I said a need a frame or applet be scrollanle and using awt.
Thanks
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Philip,
As you might have already guessed, ScrollPane only takes one child. You need to place all your components into a panel and then add the panel into the scrollPane.
Regards,
Manfred.
Philip Pross
Ranch Hand

Joined: Jan 17, 2001
Posts: 76
Thanks for the reply, and your right, so I redid my applet like so, with my applet setSize(800,400) , and my scrollpane at 800, 700. you could try my source below
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import java.io.*;
import java.net.*;
import java.applet.*;
public class ScrollPaneTest extends Applet
{
private Panel panel;
ScrollPane sp = new ScrollPane( ScrollPane.SCROLLBARS_ALWAYS );
int align = Label.CENTER;
Label lbFacture = new Label("Facture");
Label lbDate = new Label("Date");
Label lbTheDate = new Label();
Label lbFactueA = new Label("Factur� A");
Label lbLivreA = new Label("Livr� A");
Label lbVotreCom = new Label("Votre Commande");
Label lbDateCom = new Label("Date Commande");
Label lbNoCom = new Label("No de Commande Vigie");
Label lbTermCond = new Label("Terms et Conditions");
Label lbNoTaxF = new Label("No Taxe F�d�rale");
Label lbNoTaxP = new Label("No Taxe Provinciale");
Label lbRep = new Label("Repr�sentant");
Label lbNoClient = new Label("No Client");
Label lbProDes = new Label("Produit Description ",align);
Label lbQuant = new Label("Quantite",align);
Label lbQCom = new Label("Comm",align);
Label lbQSui = new Label("Suivre",align);
Label lbQLiv = new Label("Livr�",align);
Label lbUnit = new Label("Unit",align);
Label lbCode = new Label("Code",align);
Label lbCPro = new Label("Pro",align);
Label lbCFed = new Label("F�d",align);
Label lbPrix = new Label("Prix",align);
Label lbMontant = new Label("Montant",align);
Label lbModeExp = new Label("Mode Exp�dition",align);
Label lbNoBonExp = new Label("# Bon Exp",align);
Label lbDateExp = new Label("Date Exp",align);
Label lbNbr = new Label("Nbr Col",align);
Label lbPoids = new Label("Poids",align);
Label lbPayer = new Label("Veuillez payer ce montant");
List lstDetail = new List();

TextField tfFacture = new TextField();
TextField tfFacDetail1 = new TextField();
TextField tfFacDetail2 = new TextField();
TextField tfFacDetail3 = new TextField();
TextField tfFacDetail4 = new TextField();
TextField tfFacDetail5 = new TextField();
TextField tfLivre1 = new TextField();
TextField tfLivre2 = new TextField();
TextField tfLivre3 = new TextField();
TextField tfLivre4 = new TextField();
TextField tfLivre5 = new TextField();
TextField tfVotreCom = new TextField();
TextField tfDateCom = new TextField();
TextField tfNoCom = new TextField();
TextField tfTermCond = new TextField();
TextField tfNoTaxF = new TextField();
TextField tfNoTaxP = new TextField();
TextField tfRep = new TextField();
TextField tfNoClient = new TextField();
TextField tfModeExp = new TextField();
TextField tfNoBonExp = new TextField();
TextField tfDateExp = new TextField();
TextField tfNbr = new TextField();
TextField tfPoids = new TextField();
TextField tfTotalMont = new TextField();
Button btColse = new Button("Fermer");
public void init()
{
panel = new Panel();
panel.setLayout(null);
setSize(800,400);
//setLayout(null);

lbFacture.setFont(new java.awt.Font("Dialog", 1, 12));
lbDate.setFont(new java.awt.Font("Dialog", 1, 12));
lbQCom.setFont(new java.awt.Font("Dialog", 0, 9));
lbQSui.setFont(new java.awt.Font("Dialog", 0, 9));
lbQLiv.setFont(new java.awt.Font("Dialog", 0, 9));
lbCFed.setFont(new java.awt.Font("Dialog", 0, 9));
lbCPro.setFont(new java.awt.Font("Dialog", 0, 9));
tfFacture.setFont(new java.awt.Font("Dialog", 1, 12));

lbFacture.setBounds(new Rectangle(19, 25, 84, 21));
lbDate.setBounds(new Rectangle(412, 25, 84, 21));
lbTheDate.setBounds(new Rectangle(601, 10, 143, 21));
lbFactueA.setBounds(new Rectangle(15, 44, 103, 28));
lbLivreA.setBounds(new Rectangle(412, 41, 103, 28));
lbVotreCom.setBounds(new Rectangle(17, 163, 117, 21));
lbDateCom.setBounds(new Rectangle(148, 164, 117, 21));
lbNoCom.setBounds(new Rectangle(288, 165, 139, 21));
lbTermCond.setBounds(new Rectangle(447, 163, 312, 21));
lbNoTaxF.setBounds(new Rectangle(15, 215, 117, 21));
lbNoTaxP.setBounds(new Rectangle(146, 216, 117, 21));
lbRep.setBounds(new Rectangle(286, 217, 139, 21));
lbNoClient.setBounds(new Rectangle(445, 215, 312, 21));
lbProDes.setBounds(new Rectangle(13, 266, 241, 21));
lbQuant.setBounds(new Rectangle(254, 265, 129, 23));
lbQCom.setBounds(new Rectangle(254, 289, 43, 23));
lbQSui.setBounds(new Rectangle(297, 289, 43, 23));
lbQLiv.setBounds(new Rectangle(340, 289, 43, 23));
lbUnit.setBounds(new Rectangle(381, 264, 59, 23));
lbCode.setBounds(new Rectangle(438, 265, 94, 23));
lbCFed.setBounds(new Rectangle(439, 289, 47, 23));
lbCPro.setBounds(new Rectangle(485, 289, 47, 23));
lbPrix.setBounds(new Rectangle(531, 266, 101, 23));
lbMontant.setBounds(new Rectangle(632, 265, 128, 23));
lbModeExp.setBounds(new Rectangle(18, 541, 152, 21));
lbNoBonExp.setBounds(new Rectangle(170, 541, 90, 21));
lbDateExp.setBounds(new Rectangle(258, 541, 75, 21));
lbNbr.setBounds(new Rectangle(330, 541, 72, 21));
lbPoids.setBounds(new Rectangle(403, 541, 74, 21));
lbPayer.setBounds(new Rectangle(486, 543, 151, 24));
//tfFacture.setBounds(new Rectangle(117, 25, 143, 20));
tfFacture.setBounds(new Rectangle(137, 25, 222, 20));
tfFacDetail1.setBounds(new Rectangle(137, 46, 222, 23));
tfFacDetail2.setBounds(new Rectangle(137, 69, 222, 23));
tfFacDetail3.setBounds(new Rectangle(137, 91, 222, 23));
tfFacDetail4.setBounds(new Rectangle(136, 115, 222, 23));
tfFacDetail5.setBounds(new Rectangle(135, 138, 222, 23));
tfLivre1.setBounds(new Rectangle(530, 44, 222, 23));
tfLivre2.setBounds(new Rectangle(530, 66, 222, 23));
tfLivre3.setBounds(new Rectangle(530, 88, 222, 23));
tfLivre4.setBounds(new Rectangle(529, 112, 222, 23));
tfLivre5.setBounds(new Rectangle(528, 135, 222, 23));
tfVotreCom.setBounds(new Rectangle(17, 184, 101, 20));
tfDateCom.setBounds(new Rectangle(148, 185, 101, 20));
tfNoCom.setBounds(new Rectangle(290, 185, 130, 20));
tfTermCond.setBounds(new Rectangle(448, 185, 310, 20));
tfNoTaxF.setBounds(new Rectangle(14, 236, 101, 20));
tfNoTaxP.setBounds(new Rectangle(145, 237, 101, 20));
tfRep.setBounds(new Rectangle(287, 237, 130, 20));
tfNoClient.setBounds(new Rectangle(448, 237, 310, 20));
tfModeExp.setBounds(new Rectangle(17, 563, 154, 20));
tfNoBonExp.setBounds(new Rectangle(170, 563, 90, 20));
tfDateExp.setBounds(new Rectangle(260, 563, 73, 20));
tfNbr.setBounds(new Rectangle(333, 563, 70, 20));
tfPoids.setBounds(new Rectangle(404, 563, 74, 20));
tfTotalMont.setBounds(new Rectangle(636, 543, 126, 22));
lstDetail.setBounds(new Rectangle(13, 310, 747, 227));
btColse.setBounds(new Rectangle(638, 569, 129, 29));
panel.add(lbFacture, null);
panel.add(lbDate, null);
panel.add(lbTheDate, null);
panel.add(lbFactueA, null);
panel.add(lbLivreA, null);
panel.add(lbVotreCom, null);
panel.add(lbDateCom, null);
panel.add(lbNoCom, null);
panel.add(lbTermCond, null);
panel.add(lbNoTaxF, null);
panel.add(lbNoTaxP, null);
panel.add(lbRep, null);
panel.add(lbNoClient, null);
panel.add(lbProDes, null);
panel.add(lbQuant, null);
panel.add(lbQCom, null);
panel.add(lbQSui, null);
panel.add(lbQLiv, null);
panel.add(lbUnit, null);
panel.add(lbCFed, null);
panel.add(lbCPro, null);
panel.add(lbCode, null);
panel.add(lbPrix, null);
panel.add(lbMontant, null);
panel.add(lbModeExp, null);
panel.add(lbNoBonExp, null);
panel.add(lbDateExp, null);
panel.add(lbNbr, null);
panel.add(lbPoids, null);
panel.add(lbPayer, null);
panel.add(tfFacture, null);
panel.add(tfFacDetail1, null);
panel.add(tfFacDetail2, null);
panel.add(tfFacDetail3, null);
panel.add(tfFacDetail4, null);
panel.add(tfFacDetail5, null);
panel.add(tfLivre1, null);
panel.add(tfLivre2, null);
panel.add(tfLivre3, null);
panel.add(tfLivre4, null);
panel.add(tfLivre5, null);
panel.add(tfVotreCom, null);
panel.add(tfDateCom, null);
panel.add(tfNoCom, null);
panel.add(tfTermCond, null);
panel.add(tfNoTaxF, null);
panel.add(tfNoTaxP, null);
panel.add(tfRep, null);
panel.add(tfNoClient, null);
panel.add(tfModeExp, null);
panel.add(tfNoBonExp, null);
panel.add(tfDateExp, null);
panel.add(tfNbr, null);
panel.add(tfPoids, null);
panel.add(tfTotalMont, null);
panel.add(lstDetail, null);
panel.add(btColse, null);
sp.setBounds(0, 0, 800, 700);
sp.add(panel);
add(sp);
}
But now the scroll is like not enabled, it greyed out
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Phillip,
After looking at your code I figured out the following problems.
1. You must set some size on your 'panel'. Since you have set its layout to null, the scrollPane assumes it is the same size as itself. Therefore you get no scrolling! Replace the line:
sp.setBounds( 0, 0, 800, 400 );
with the following:
panel.setBounds( 0, 0, 800, 400 );
This will give you some scrollbars that work.
2. You need to set the Applet layout to BorderLayout and place your sp in the center. This will allow the scrollPane to be as big as your HTML code says it should be. The following lines at the end of your init method (just before the last add call) should work:
setLayout( new BorderLayout() );
This will make the sp as large as the applet.
Regards,
Manfred.
Philip Pross
Ranch Hand

Joined: Jan 17, 2001
Posts: 76
Thanks alot I got it working perfectly
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ScrollPane