|
-
Nov 20th, 2008, 06:04 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Placing objects.
ok, i'm tierd of using things such as:
Code:
frame.add(textArea, "North");
frame.add(textField, "South");
frame.add(Button, "East");
how can i place it where i want my self, instead of north, south, east or west?
ps. i'm not using anything to design my programs, i just use plain codes.
Last edited by Justa Lol; Nov 20th, 2008 at 06:07 PM.
-
Nov 20th, 2008, 07:03 PM
#2
Re: Placing objects.
you can set the layout to null and use Component.setLocation. Or if you're using Java6 you can use the GroupLayout from the javax.swing package
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Nov 20th, 2008, 08:08 PM
#3
Thread Starter
Fanatic Member
Re: Placing objects.
i have jdk and jre6u10 if thats what you mean? but can you tell me how exactly to use those?
Last edited by Justa Lol; Nov 20th, 2008 at 08:16 PM.
-
Nov 20th, 2008, 08:54 PM
#4
Re: Placing objects.
Code:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Test
{
public static void main(final String[] args)
{
final JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(null);
final JButton btn = new JButton();
btn.setLocation(10, 10);
btn.setSize(100, 20);
btn.setText("I'm a button");
btn.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(final ActionEvent e)
{
JOptionPane.showMessageDialog(null, "I'm a message box");
}
});
frame.add(btn);
frame.setSize(200, 200);
frame.setVisible(true);
}
}
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|