MrMcAero
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
|
| 03 May 2012 03:52 PM |
So, I want to create a JButton, inside a JFrame with the size of (25,25), and at a position of (25,25): here's my code. import javax.swing.*; public class mainJFrame{ public static void main(String[] args){ JFrame frame = new JFrame("ROBLOX Plugin Template"); frame.setSize(400, 200); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create a button JButton button = new JButton(); button.setLocation(25,25); button.setSize(0,0); //Add the button frame.getContentPane().add(button); } }
- Cheers! |
|
|
| Report Abuse |
|
|
MrMcAero
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
|
| 03 May 2012 03:53 PM |
Also, it create's a button the size of the whole JFrame, no matter what I set the [button.setSize(X,X);]
- Cheers! |
|
|
| Report Abuse |
|
|
su8
|
  |
| Joined: 06 Mar 2009 |
| Total Posts: 6334 |
|
|
| 03 May 2012 04:06 PM |
Posts here should be about rbx.lua
inb4brandon |
|
|
| Report Abuse |
|
|
MrMcAero
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
| |
|
| |
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 03 May 2012 04:16 PM |
You need to change the layout style for the object. What the "size" property is actually used for depends on the layout scheme, and it isn't used at all by the default scheme.
Search "swing layouts" for more info. I don't know enough about them to give you the right one for your situation off the top of my head. |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 03 May 2012 04:16 PM |
| Try setting it to 0.5, 0.5... |
|
|
| Report Abuse |
|
|
MrMcAero
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
|
| 03 May 2012 04:52 PM |
When setting the size to [(0.5,0.5)], I get NO button, and an error saying something like "I hate decimal's". :\
- Cheers! |
|
|
| Report Abuse |
|
|
MrMcAero
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
|
| 03 May 2012 04:54 PM |
When using GridLayout (Do I need to import it), I get an error:
cannot find symbol symbol: class GridLayout location: class mainJFrame
frame is already defined in main(java.lang.String[])
- Cheers! |
|
|
| Report Abuse |
|
|
|
| 03 May 2012 05:08 PM |
In order to set specific positions and sizes, you need an absolute layout.
`frame.setLayout(null);`
You can also reduce the method calls when sizing your button by using the `setBounds` method.
import javax.swing.*; public class mainJFrame{ public static void main(String[] args){ JFrame frame = new JFrame("ROBLOX Plugin Template"); frame.setSize(400, 200); frame.setVisible(true); frame.setLayout(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create a button JButton button = new JButton(); button.setBounds(25,25,25,25); // x, y, width, height //Add the button frame.getContentPane().add(button); } } |
|
|
| Report Abuse |
|
|
MrMcAero
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
|
| 03 May 2012 07:55 PM |
So setBounds, does Location(X,Y) and Size(X,Y)?
- Cheers! |
|
|
| Report Abuse |
|
|
|
| 04 May 2012 06:02 PM |
Indeed,
https://docs.oracle.com/javase/1.4.2/docs/api/java/awt/Component.html#setBounds(int, int, int, int) |
|
|
| Report Abuse |
|
|