Sunday, February 12, 2012

Using absolute positioning

All Java components have a platform-dependent, preferred size. This specifies how large the component should be, notwithstanding the layout policy of the layout manager used by its container. A component's preferred size is usually the size that is big enough for a user to see its function on a GUI.
You can use absolute positioning in conjunction with a layout manager to position components. When using absolute positioning, you are required to specify the size and position of each component within the container. You can modify a component's position and size by using the Component class's setBounds method.

public void setBounds(int x, int y, int width, int height);

When a layout manager lays out components, it takes into account its own layout policy and the preferred sizes of its container's components.

If there is a clash between the layout policy of the layout manager and the preferred size of a component that it is positioning, the layout policy takes precedence.

For example, if a button's preferred size is larger than the size and position required by the layout manager's layout policy, the button will be resized by the layout manager.

The Component class has instance variables that specify the size and position of components.
The variables x and y specify the component's position in pixels, relative to the top left-hand corner of its container.

The width and height variables are also measured in pixels.
To use absolute positioning, you need to set the container's layout property to null.

public class LayoutApplet extends Applet {
import java.awt.*;
import java.applet.Applet;

public class NewButton extends Applet {
  public void init (){
    MISSING CODE
  }
}
public class LayoutApplet extends Applet {
import java.awt.*;
import java.applet.Applet;

public class NewButton extends Applet {
  public void init (){
    setLayout (null);
  }
}

You type setLayout (null); to set the layout property to null.
To set the container's layout property to null, you call the setLayout method and give it a parameter of null.

import java.awt.*;
import java.applet.Applet;

public class NewButton extends Applet {
  public void init (){
    setLayout (null);
  }
}

Note

Using absolute positioning for all components on your interface is not advised because components aren't implemented consistently across platforms. Components also don't resize well when you resize the top-level container. You should use absolute positioning only when it is really necessary.
Consider the code in which you add a button to the applet NewButton. Its position is four pixels in and six pixels down from the top left-hand corner of the container. You also specify the size of the button – 200 pixels wide and 400 pixels high.
import java.awt.*;
import java.applet.Applet;

public class NewButton extends Applet {
  public void init (){
    setLayout (null) ;
    Button b = new Button ("Exit");
    b.setBounds(4,6,200,400);
    add(b);
  }
}
When you run the NewButton applet, the button appears the exact size defined in the setBounds method. This is because the applet is not using the layout manager class.

This may cause only part of the button to be shown or the button may not be visible at all. You may need to resize the JFrame window to see the button.

import java.awt.*;
import java.applet.Applet;

public class NewButton extends Applet {
  public void init (){
    setLayout (null) ;
    Button b = new Button ("Exit");
    b.setBounds(4,6,200,400);
    add(b);
  }
}

74 comments:

PHP scripting is definitely one of the easiest, if not the easiest scripting language to learn and grasp for developers. This is partially due to the similarities PHP syntax has with C and Java. Even if the only knowledge of development that you have is with HTML, picking up PHP is still fairly easy.
PHP training in Chennai|PHP training institute in Chennai|PHP course in Chennai

Thanks for sharing the wonder article, SAS is the recent technology, you must learn this valuable course to get future in IT firm.
Regards,
SAS Training in Chennai|SAS Training in Chennai

And that I guess I could come up with yet another flawed solution soon. The fact is - there is no clear answer on when to say "today the page is whole" because of the eternal programs performing their work. Pick the one that serves you most readily useful, but beware of its shortcomings.

Great article, thanks for sharing usefull information and i have seen more info on
UI online training

I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here.Thanks once more for all the details.
https://www.besanttechnologies.com/training-courses/devops-training-in-bangalore

It's outstandingly useful site for learn. This present information's are to a great degree valuable to us.Performance testing training in Chennai | LoadRunner Training Institute in Chennai

Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
Devops Training in Chennai

Devops Training in Bangalore

Devops Training in pune

Thanks a lot for sharing us about this update. Hope you will not get tired on making posts as informative as this. 
python training institute in chennai
python training in velachery

I was recommended this web site by means of my cousin. I am now not certain whether this post is written through him as nobody else recognise such precise about my difficulty. You're amazing! Thank you!
Blueprism training in marathahalli

Blueprism training in btm

Blueprism online training

Awesome..You have clearly explained …Its very useful for me to know about new things..Keep on blogging..
Blueprism training in tambaram

Blueprism training in annanagar

Blueprism training in velachery

You got an extremely helpful website I actually have been here reading for regarding an hour. I’m an initiate and your success is incredibly a lot of a concept on behalf of me.

Data Science course in kalyan nagar | Data Science course in OMR
Data Science course in chennai | Data science course in velachery
Data science online course | Data science course in jaya nagar

This blog is very much helpful to us. Thanks for your information

empoweriasacademy
Education

Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.

Selenium Interview Questions and Answers

Best Selenium Training in Chennai | Selenium Training Institute in Chennai | Besant Technologies

Selenium Training in Bangalore | Best Selenium Training in Bangalore

Free Selenium Tutorial |Selenium Webdriver Tutorial |For Beginners




Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic.
python training in rajajinagar | Python training in bangalore | Python training in usa

I love the blog. Great post. It is very true, people must learn how to learn before they can learn. lol i know it sounds funny but its very true. . .

angularjs Training in bangalore

angularjs Training in bangalore

angularjs online Training

angularjs Training in marathahalli

angularjs interview questions and answers

Its really an Excellent post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog. Thanks for sharing....
python training institute in marathahalli
python training institute in btm
Python training course in Chennai

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me. I am a regular follower of your blog.
Really very informative post you shared here. Kindly keep blogging.
Java training in Btm layout
Java training in Rajaji nagar
Java training in Kalyan nagar
Java training in Kalyan nagar
Java training in Jaya nagar


You are doing a great job. I would like to appreciate your work for good accuracy
Regards,
Best Devops Training in Chennai | Best Devops Training Institute in Chennai

You have provided a nice article, Thank you very much for this one. And I hope this will be useful for many people. And I am waiting for your next post keep on updating these kinds of knowledgeable things
Devops Training in Chennai | Devops Training Institute in Chennai

Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
Devops Training in Chennai | Devops Training Institute in Chennai

Thanks for such a good collections.its very helpful for me again thank you.
Apple iPhone Service Center in Chennai Anna Nagar


Java, Python, R, Sql and may other languages are helpful in any filed related to programming languages. Specially In Data Science Certification in Pune

thank you for such a informative blog. For more

data science course in pune


Thank you. A Great knowledge shared by you Data Science certification is designed to teach specific computer programming. Kindly keep on posting these types of tutorials.Here I also want to tell them who are seeking their career in Data science certification, can check this link.
https://www.excelr.com/data-science-course-training-in-pune/

The development of artificial intelligence (AI) has propelled more programming architects, information scientists, and different experts to investigate the plausibility of a vocation in machine learning. Notwithstanding, a few newcomers will in general spotlight a lot on hypothesis and insufficient on commonsense application. Machine Learning Final Year Projects In case you will succeed, you have to begin building machine learning projects in the near future.

Projects assist you with improving your applied ML skills rapidly while allowing you to investigate an intriguing point. Furthermore, you can include projects into your portfolio, making it simpler to get a vocation, discover cool profession openings, and Final Year Project Centers in Chennai even arrange a more significant compensation.


Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account.

Awesome. I read this post so nice and very informative information...thanks for sharing.

eTechno Soft Solutions is a leading training institute for all kind of the Oracle Training in Bangalore with real-time experienced trainers with 100% Placement Assistance.

Cloud means internet that can be accessed from any geographical region. No hard disk or storage media is required for saving a file or even downloading big data. machine learning courses in hyderabad

Wow! Such an amazing and helpful post this is. I really really love it. It's so good and so awesome. I am just amazed. I hope that you continue to do your work like this in the future also.
Data Science Training in Hyderabad

I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
data scientist training and placement in hyderabad

Excellent post.I want to thank you for this informative read, I really appreciate sharing this great post.Keep up your work
data scientist training and placement

Wonderful blog post. This is absolute magic from you! I have never seen a more wonderful post than this one. You've really made my day today with this. I hope you keep this up!
data scientist training and placement in hyderabad

This is my first time i visit here. I found so many interesting stuffs in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work
Data Science Training in Hyderabad
Data Science Course in Hyderabad

Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts.
DevOps Training in Hyderabad
DevOps Course in Hyderabad

Thanks for the article on absolute positioning,keep sharing.


Data Science Training in Pune

I curious more interest in some of them hope you will give more information on this topics in your next articles.
data science course

This is an excellent post I seen thanks to share it. It is really what I wanted to see hope in future you will continue for sharing such a excellent post.
data science course

You completely match our expectation and the variety of our information.
data science course

The worst part of it was that the software only worked intermittently and the data was not accurate. You obviously canot confront anyone about what you have discovered if the information is not right. data science course in mysore

The next time I read a blog, I hope that it doesnt disappoint me as much as this one. I mean, I know it was my choice to read, but I actually thought you have something interesting to say. All I hear is a bunch of whining about something that you could fix if you werent too busy looking for attention.data science course in surat

Post a Comment