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
posted
0
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
posted
0
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();
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.