Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Cannot align JTextField in JPanel

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    40
    My Mood
    Sneaky
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Cannot align JTextField in JPanel

    I'm writing a GUI for a DVD player. I'm attempting to align the JTextField to the center of the JPanel, but I am getting this error:

    DVDPlayer.java:23: cannot find symbol
    symbol : method setVerticalAlignment(int)
    location: class javax.swing.JTextField
    jtfDetails.setVerticalAlignment(JTextField.CENTER) ;
    ^
    1 error

     import javax.swing.*;
    import java.awt.*;
    import javax.swing.border.*;
     
    public class DVDPlayer extends JFrame
    {
    	private JPanel p1, p2;
    	private JButton jbtDVD, jbtPlay, jbtRewind, jbtFForward, jbtStop;
    	private JTextField jtfDetails;
     
    	public DVDPlayer()
    	{
    		add(jbtDVD = new JButton("DVD to be placed here"));
    		add(jbtDVD, BorderLayout.NORTH);
     
    		p1 = new JPanel();
    		p1.add(jtfDetails = new JTextField("DVD details to be displayed here"));
    		jtfDetails.setVerticalAlignment(JTextField.CENTER);
     
    		add(p1, BorderLayout.WEST);
     
    		p2 = new JPanel();
    		p2.setLayout(new FlowLayout());
    		p2.setBorder(new LineBorder(Color.BLACK, 2));
    		p2.add(jbtPlay = new JButton("Play"));
    		p2.add(jbtRewind = new JButton("<<"));
    		p2.add(jbtFForward = new JButton(">>"));
    		p2.add(jbtStop = new JButton("Stop"));
     
    		add(p2, BorderLayout.EAST);
    	}
     
    	public static void main(String[] args)
    	{
          DVDPlayer frame = new DVDPlayer();
          frame.setTitle("The Front View of a DVD Player");
          frame.pack();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
       }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Cannot align JTextField in JPanel

    The compiler can not find a definition for the symbol above the ^. What is the symbol that the compiler can't find? Posting the error message lost the position of the ^.
    Is that symbol defined? Did you spell it correctly?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Oct 2011
    Posts
    40
    My Mood
    Sneaky
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Re: Cannot align JTextField in JPanel

    The symbol above the ^ is the . between 'jtfDetails' and 'setVerticalAlignment'. Yes it is spelt correctly.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Cannot align JTextField in JPanel

    What class is that method defined in? The compiler can't find it in the JTextField class.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Oct 2011
    Posts
    40
    My Mood
    Sneaky
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Re: Cannot align JTextField in JPanel

    It's defined in the JLabel class. setVerticalAlignment isn't defined in the JTextField class, so does that mean I must use a different method?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Cannot align JTextField in JPanel

    must use a different method?
    You must use a method that belongs to the class of the variable.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How to align text? Printf?
    By shifat96 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 20th, 2012, 12:51 PM
  2. How to align text?
    By shifat96 in forum Java Theory & Questions
    Replies: 4
    Last Post: February 20th, 2012, 12:15 PM
  3. Can't seem to align the numbers
    By Wilkinsonr in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 29th, 2012, 05:37 PM
  4. Display a JTextField inside a JPanel
    By nivangerow in forum What's Wrong With My Code?
    Replies: 13
    Last Post: January 8th, 2012, 01:28 PM
  5. How do you align?
    By JavaStudent1988 in forum Java Theory & Questions
    Replies: 5
    Last Post: October 18th, 2011, 05:33 PM