Приведенный ниже код вернет JTextField с черным фоном и красным текстом.
import javax.swing.JTextField;
import javax.swing.JFrame;
import java.awt.Color;
import java.awt.FlowLayout;
public class test
{
public static void main(String[] args)
{
JTextField textField = new JTextField(20);
JFrame frame = new JFrame("Java"); // Just the window title, name doesn't matter
frame.setLayout(new FlowLayout());
Color color = new Color(255,0,0); // Set the text color
textField.setBackground(Color.BLACK); // Set the black background
textField.setForeground(color);
frame.add(textField);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500,200);
frame.setVisible(true);
}
}
JTextField наследует getBackground()
и getForeground()
от Component. Если я понимаю ваш вопрос, это должно дать вам значения.