How to position components i.e. buttons on jframe ? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

How to position components i.e. buttons on jframe ?

10th Feb 2017, 10:16 AM
Sam
3 Respuestas
+ 1
I typically use JPanels and BorderLayout.. I make my JFrame. then I make my Panels.. then I add them to my frame. I add my buttons to my panels.. for instance, if I wanted my button on the bottom, I would do something like this.. Button mybutton = new Button("Click Me"); JFrame win = new JFrame(); JPanel bottom = new JPanel(); win.add(bottom, BorderLayout.PAGE_END); Then I would add my button to the bottom panel bottom.add(mybutton);
10th Feb 2017, 10:46 AM
LordHill
LordHill - avatar
0
Thank you very much for you time. i have used the same method yours.However I have three buttons and one label. I want my three buttons to show under the label. So I would like the label to show at the top of the screen and the buttons underneath. I have tried the Borderlayout, GridBagLayout and FlowLayout but none seem to be working
12th Feb 2017, 2:23 PM
Sam
0
there are two ways to set a component : 1. using Functn setBounds(x,y,width,height); 2. Using Graphical method . just by dragging component to desired location Graphical method can be implemented using Netbeans IDE it is preinstalled plugin whereas in eclipse u need to install the plugin .
21st Apr 2017, 2:21 AM
Yash Tiwari
Yash Tiwari - avatar