The Artima Developer Community
Sponsored Link

Java Answers Forum
precise positioning of ocmponents

4 replies on 1 page. Most recent reply: Nov 20, 2002 3:42 PM by twisty

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Karen Reyes

Posts: 2
Nickname: biach
Registered: Nov, 2002

precise positioning of ocmponents Posted: Nov 19, 2002 3:16 AM
Reply to this message Reply
Advertisement
i jsut wanted to know how or what to use ot precisely put textarea components in an applet....i understand i need not use layout manager on this.
also,is there any way where i can draw string or write text to a drawrect (rectangle)???


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: precise positioning of ocmponents Posted: Nov 19, 2002 10:02 AM
Reply to this message Reply
Borland's JBuilder has a layout manager that lets you use absolute coordinates. Maybe you can use it, or maybe there are open source layout managers that do the same.

As for drawing text, you can call graphics.drawString() in paintComponent(), where graphics is the Graphics object passed to that method.

twisty

Posts: 22
Nickname: twisty
Registered: Nov, 2002

Re: precise positioning of ocmponents Posted: Nov 19, 2002 2:41 PM
Reply to this message Reply
Using a null layout will allow you to place you controls exactly where you want them.

Karen Reyes

Posts: 2
Nickname: biach
Registered: Nov, 2002

Re: precise positioning of ocmponents Posted: Nov 20, 2002 6:27 AM
Reply to this message Reply
uhm i tried settin the layout to null but the component wont show up in the applet....when i tried takin the setlayout(null) command out of the program just the add(button)...etc..it jsut fills the whole screen!!...i tried usin grid layout and gridbagconstraints but theyre jst confusin me coz they keep on overlapping :(
is the setlocation thingy work?if it does,how?coz i cant seem to make it work without the component fillin the whole screen.....

twisty

Posts: 22
Nickname: twisty
Registered: Nov, 2002

Re: precise positioning of ocmponents Posted: Nov 20, 2002 3:42 PM
Reply to this message Reply
Heres a small example for you:
// NullApplet.java
 
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
 
 
public class NullApplet extends JApplet {
	
	JPanel mainPanel = new JPanel();
	JTextField textField = new JTextField();
	JButton button = new JButton();
	
	public void init() {
		this.setSize(new Dimension(400,300));
		mainPanel.setLayout(null);
		textField.setBounds(new Rectangle(18, 98, 237, 36));
		button.setBounds(new Rectangle(258, 98, 58, 36));
		button.setText("Clicky");
		this.getContentPane().add(mainPanel, BorderLayout.CENTER);
		mainPanel.add(textField, null);
		mainPanel.add(button, null);
	}
 
}

The html is:

<HTML>
<HEAD>
</HEAD>
<BODY BGCOLOR="000000">
<CENTER>
<APPLET
code = "NullApplet.class"
width = "500"
height = "300"
>
</APPLET>
</CENTER>
</BODY>

<script language="JavaScript">
<!--

window.open = SymRealWinOpen;

//-->
</script>

</HTML>

Flat View: This topic has 4 replies on 1 page
Topic: I made a Applet... Previous Topic   Next Topic Topic: help with inserting into a database

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use