Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my code

C#
UserNameTextBox = new JTextField();
    UserNameTextBox.setHorizontalAlignment(SwingConstants.CENTER);
    UserNameTextBox.setBounds(562, 326, 119, 20);
    contentPane.add(UserNameTextBox);
    UserNameTextBox.setColumns(10);

    UserNameTextBox.getDocument().addDocumentListener(new DocumentListener() {
      public void changedUpdate(DocumentEvent e) {
          UserNameTextBox.setBackground(Color.red);
      }
      public void removeUpdate(DocumentEvent e) {
          UserNameTextBox.setBackground(Color.red);
      }
      public void insertUpdate(DocumentEvent e) {
          UserNameTextBox.setBackground(Color.red);
      }
});


the problem is, is that nothing happens when I type in the textfeild, its meant to go red, can some one please explain why its not wokring? im so confused
Posted
Comments
Shubhashish_Mandal 20-Jul-13 14:09pm    
Nothing is wrong in the code
[no name] 20-Jul-13 19:48pm    
so the code works for you? because its not for me, can you please give me an example of where it goes? coz I might have put it in the wrong spot
Shubhashish_Mandal 21-Jul-13 2:27am    
yes I have tested it and works fine.If it is not work in your case then post the rest of the code may be the glitch is there.
[no name] 21-Jul-13 3:29am    
its allot but here is all the code



package me.codplaymakers.com;

import java.awt.BorderLayout;

public class MainScreen extends JFrame {

private JPanel contentPane;

private ImageIcon image1;
private JLabel FaceImage;

private ImageIcon image2;
private JLabel FrontImage;

private ImageIcon image3;
private JLabel BackImage;

private ImageIcon image4;
private JLabel ThreeDImage;
private JTextField UserNameTextField;



/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {


public void run() {
try {
MainScreen frame = new MainScreen();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});

}




/**
* Create the frame.
* @throws IOException
*/
public MainScreen() throws IOException {
setResizable(false);
setTitle("Skin Stealer Pro beta");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 717, 410);
contentPane = new JPanel();
contentPane.setBackground(new Color(0, 100, 0));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

JButton btnDownloadFace = new JButton("Download Face");
btnDownloadFace.setBackground(new Color(0, 100, 0));
btnDownloadFace.setBounds(562, 175, 119, 23);
contentPane.add(btnDownloadFace);

JButton btnDownloadBody = new JButton("Download Body");
btnDownloadBody.setBackground(new Color(0, 100, 0));
btnDownloadBody.setBounds(562, 209, 119, 23);
contentPane.add(btnDownloadBody);

//edit here, added image-----------------------------
//face
URL url = new URL("http://minecraft.aggenkeech.com/face.php?u=z3nox");
image1 = new ImageIcon(ImageIO.read(url));
FaceImage = new JLabel(image1);
FaceImage.setHorizontalAlignment(SwingConstants.LEFT);
FaceImage.setVerticalAlignment(SwingConstants.TOP);
FaceImage.setBounds(550, 11, 65, 60);
contentPane.add(FaceImage);

//front
URL url2 = new URL("http://mcskinsearch.com/img/cache/pic/z3nox.png");
image2 = new ImageIcon(ImageIO.read(url2));
image2 = new ImageIcon(image2.getImage().getScaledInstance(297, 297, BufferedImage.SCALE_SMOOTH));
FrontImage = new JLabel(image2);
FrontImage.setHorizontalAlignment(SwingConstants.LEFT);
FrontImage.setVerticalAlignment(SwingConstants.TOP);
FrontImage.setBounds(10, 11, 151, 297);
contentPane.add(FrontImage);

//back
URL url3 = new URL("http://mcskinsearch.com/img/cache/pic/z3nox.png");
image3 = new ImageIcon(ImageIO.read(url3));
image3 = new ImageIcon(image3.getImage().getScaledInstance(297, 297, BufferedImage.SCALE_DEFAULT));
BackImage = new JLabel(image3);
BackImage.setVerticalAlignment(SwingConstants.TOP);
BackImage.setHorizontalAlignment(SwingConstants.RIGHT);
BackImage.setBounds(171, 11, 151, 297);
contentPane.add(BackImage);
//end edit--------------------------------




JButton btnDownloadSkin = new JButton("Download Skin");
btnDownloadSkin.setBackground(new Color(0, 100, 0));
btnDownloadSkin.setBounds(562, 243, 119, 23);
contentPane.add(btnDownloadSkin);

JButton btnChangeSkin = new JButton("Change Skin");
btnChangeSkin.setBackground(new Color(0, 100, 0));
btnChangeSkin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
btnChangeSkin.setBounds(562, 277, 119, 23);
contentPane.add(btnChangeSkin);

JLabel lblUsersName = new JLabel("Users Name");
lblUsersName.setBounds(597, 311, 72, 14);
contentPane.add(lblUsersName);

Label label = new Label("Created By: TechXSoftware");
label.setForeground(new Color(0, 0, 205));
label.setBounds(540, 352, 151, 22);
contentPane.add(label);

Label label_1 = new Label("Face");
label_1.setFont(new Font("Dialog", Font.BOLD, 20));
label_1.setBounds(560, 77, 48, 22);
contentPane.add(label_1);

Label label_2 = new Label("Front");
label_2.setFont(new Font("Dialog"
[no name] 21-Jul-13 3:30am    
label_2.setBounds(56, 314, 54, 22);
contentPane.add(label_2);

Label label_3 = new Label("Back");
label_3.setFont(new Font("Dialog", Font.BOLD, 20));
label_3.setBounds(224, 314, 48, 22);
contentPane.add(label_3);

UserNameTextField = new JTextField();
UserNameTextField.setHorizontalAlignment(SwingConstants.CENTER);
UserNameTextField.setBorder(BorderFactory.createLineBorder(Color.black));
UserNameTextField.addInputMethodListener(new InputMethodListener() {
public void caretPositionChanged(InputMethodEvent arg0) {
}
public void inputMethodTextChanged(InputMethodEvent arg0) {
UserNameTextField.setBackground(Color.red);
}
});
UserNameTextField.setBounds(562, 326, 119, 20);
contentPane.add(UserNameTextField);
UserNameTextField.setColumns(10);
}
}

1 solution

Interesting apporaches in the comments here.
I've never used any of them, but hey(!) - there is always a first time...

http://docs.oracle.com/javase/tutorial/uiswing/components/textfield.html[^]

I recommend an ActionListener.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900