Author | Topic: applets |
Prasad unregistered |
posted February 02, 2000 04:06 AM
import java.applet.*; import java.awt.*; public class Q20 extends Applet please tell me as to why the above applet behaves the way it does. I expect it to display five buttons positioned in five respective places. But only the 'Center' button is being displayed. prasad
|
Tony Alicea sheriff |
posted February 02, 2000 09:35 AM
The correct way is add(Component c, Object Constraints) That translates to add(okButton, "North") although I prefer add(okButton, BorderLayout.NORTH)
|
maha anna bartender |
posted February 02, 2000 01:18 PM
Hi Tony! I was testing prasad's program and I came to know the foll. The problem is not the syntax. Both add("North",bn) and add(bn,GridBagLayout.NORTH) are correct . This problem happens ONLY WHEN WE ADD THE SAME OBJECT again and again. It does not happen when we add diff objects it works fine. I created 5 diff btns and added them and it worked fine also. The same this happens when we change the Layout to FlowLayout also. It appears as though when we add the same object again the layout manager just clears the old place... For simplicity I changed this as an application. The same thing happens in applet also. Do you have any idea why this happens.... code: [I split one overlong line in the code - Jim] [This message has been edited by Jim Yingst (edited February 02, 2000).]
|
Paul Wheaton sheriff |
posted February 02, 2000 06:22 PM
The layout manager keeps track of all the objects added. Later you can call remove( component ) and it will remove the one component that you reference. So if you add the same component, it isn't really added, it sort of replaces the previous instance of the component.
|
| | |