Share on Google+Share on Google+

1 Answer(s)      6 years and 2 months ago
Posted in : Java Beginners

How to align the controls in java?


View Answers

February 2, 2011 at 2:58 PM

Hi Friend,

Try this:

import javax.swing.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;

class LoginDemo extends JFrame{
 JButton SUBMIT;
 JLabel label1,label2;
 final JTextField  text1,text2;
    setTitle("Login Form");
    label1 = new JLabel();
    text1 = new JTextField(15);

    label2 = new JLabel();
    text2 = new JPasswordField(15);

    SUBMIT=new JButton("SUBMIT");

  public static void main(String arg[]){
  new LoginDemo();

And if you want to use layouts then please visit the following:

BoxLayout Example

GridBagLayout Example

GridLayout Example

SpringLayout Example


Related Tutorials/Questions & Answers:
Tooltip Alignment
alignment of that tooltip as desired.The Div is seen in the other position other than
Tooltip alignment
alignment of that tooltip as desired.The Div is seen in the other position other than
alignment for header and footer
alignment for header and footer  header and footer alignment is not fit like footer is not fit in bottom some white space is there in jsf, what to do
how to make a label left alignment?
how to make a label left alignment?  how to make a label left alignment
Alignment in struts 2.0 - Struts
Alignment in struts 2.0  Hi, I am working in Struts 2.0. I have 2 queries. 1) I have used tr and td but i am not able to align in center. 2)label and textfield are not coming in same line. indentation is not proper
Alignment in the Dojo Date Widget - Ajax
Alignment in the Dojo Date Widget  Is there any way to align misaligned text in a dojo date widget?   Hi Friend, Please visit the following links:
Alignment of Image in HTML
Alignment of Image in HTML       The Tutorial illustrates an example from Alignment of image in HTML. In this Tutorial, the code explain an alignment of image in HTML
Make Paragraph and Set Alignment
alignment. To make a paragraph we use Paragraph("Text") constructor . To gives alignment we use setAlignment(int alignment). Code Description: setAlignment(int alignment): We can set
Working With Alignment Using JSP for Excel
Working with alignment using jsp for excel  ... alignment of cells on an excel sheet. The packages we need to import are setAlignment(HSSFCellStyle.ALIGN_CENTER): This method is used to set the alignment
Set Space Ratio and Alignment
alignment. You can make pdf with no space between the characters of a word . Code Description: setAlignment(int alignment... alignment). The alignment can be one of the following values
Swing UI alignment Issue on different Platform - Swing AWT
Swing UI alignment Issue on different Platform  Hi, We are developing screens using Java Swing on windows. The problem is when we take the same screen in Linux machine, The alignment is changing. This is happening if we change
Swing UI alignment Issue on different Platform - Swing AWT
Swing UI alignment Issue on different Platform  Hi, We are developing UI using Java Swing on windows. The problem is when we Test the same Ui... of the buttons are not displaying on the UI and panel alignment is also getting
Using HeaderFooter class of iText API , Can we display multiple phrases in the footer section of PDF ,each with different alignment.
Using HeaderFooter class of iText API , Can we display multiple phrases in the footer section of PDF ,each with different alignment.  Hi, I have a similar question related to HeaderFooter class, I want to display three Phrases
While retrieving text from database onto JSP, the alignment of line and paragraphs is not followed
While retrieving text from database onto JSP, the alignment of line and paragraphs is not followed  I have stored text database through textarea box. While trying to retrieve the same text from db, the text displayed onto
Align Text MIDlet Example
want in our application. Similarly we can also set the different alignment... such as right, left, top right and top left etc.. to set the alignment we have
itext pdf
itext pdf  i am generating pdf using java i want to do alignment in pdf using java but i found mostly left and right alignment in a row. i want to divide single row in 4 parts then how can i do
jquery dialog box center
jquery dialog box center  How to create dialog box with center alignment in jquery..?   $('my-selector').dialog('option', 'position', 'center
X-Chat       X-Chat has two good features of usability: colored nicknames and alignment by text as opposed to alignment by nicks. When you read text, it's enough for eyes to notice
Java Layout
. Components can provide size and alignment hints, still the container's layout manager has... and Alignment Hints Putting Space Between Components Setting the Container's
Vertically center page
Vertically center page  I know how to center the text of the page Horizontally ..but is it possible to vertically center page in HTML or CSS?   You can set the Height, width and left, right alignment for the text in CSS
Tags Alignemnt - Struts
Tags Alignemnt  How to align these form tags in a table? When i tryied to add in table i am getting the improper alignment. I used the datetimepicker, selec etc in struts2, Please any body help me to get thesealignment in proper
Java EE 8 Takes Off
the support for HTTP 2/HTML 5, CDI/managed bean alignment, cloud support in Java and the Java SE alignment. These features seems good as for now. Here... More support for Hypermedia Looking into further JSF alignment
CSS hack for Opera9.63 - Java Beginners
CSS hack for Opera9.63  Hi All, I am terribly stuck with a serious Opera 9.63 related issue .Actually I need my application to be tested in IE,FF,Chrome,Safari and Opera 9.63.I have an alignment problem in Opera 9.63
java code - Java Beginners
java code  PROGRAM FOR RIGHT ALIGNMENT i.e INPUT: Enter any sentence: "This is JAVA" (which is displaying on the left side in the console i.e on cmd prompt) OUTPUT: "This is JAVA" (should
iphone Window Based Application
with different frame, font, size and alignment. Creating variable for label on view...] initWithFrame:CGRectMake(80,80, 200, 100)];  Insertingtext into label and alignment...; // is for alignment  Textcolor which is printed on label and font
combobox updation - Java Beginners
); jpanel.add(lable2); patternList.setAlignmentX(Component.LEFT_ALIGNMENT...(result); jpanel.setAlignmentX(Component.LEFT_ALIGNMENT); resultPanel.setAlignmentX(Component.LEFT_ALIGNMENT); add(jpanel
BioInformatics Tools
Local Alignment Search Tool (BLAST) for comparing gene and protein sequences...; score. An optimized alignment that includes gaps is shown in the output as "... around 100 programs (applications) for sequence alignment, database searching
Retrieve data from the database and write into ppt file
and methods that control the alignment and anchoring of the text.With the use
Problem while using a HashMap for writing text ina RTF file. - Framework
:- public void addParagraph(Font font, String alignment, String sentences...(); //p.setAlignment(alignment); p.setAlignment(Element.ALIGN_JUSTIFIED
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? file location SASLError using PLAIN: not-authorized


Advertisement null