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
Code Java:
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);
}
}
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?
Re: Cannot align JTextField in JPanel
The symbol above the ^ is the . between 'jtfDetails' and 'setVerticalAlignment'. Yes it is spelt correctly.
Re: Cannot align JTextField in JPanel
What class is that method defined in? The compiler can't find it in the JTextField class.
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?
Re: Cannot align JTextField in JPanel
Quote:
must use a different method?
You must use a method that belongs to the class of the variable.