How do I change the way the date is inserted into my jTextField
?
What I have is the following:
IwanttoinsertthisiconthatisinjLabel
withinmyjTextField
.Isthispossible?
Update:
importjava.awt.*;importjavax.swing.*;classTestingextendsJFrame{publicTesting(){setDefaultCloseOperation(EXIT_ON_CLOSE);JPanelp=newJPanel(newBorderLayout());JTextFieldtf=newJTextField(5);JLabellabel=newJLabel(newImageIcon("LogoIcon.png"));
label.setOpaque(true);
label.setBackground(tf.getBackground());
label.setPreferredSize(new Dimension(label.getPreferredSize().width,tf.getPreferredSize().height));
p.setBorder(tf.getBorder());
tf.setBorder(null);
p.add(label,BorderLayout.WEST);
p.add(tf,BorderLayout.CENTER);
JPanel p1 = new JPanel();
p1.add(p);
getContentPane().add(p1);
pack();
setLocationRelativeTo(null);
}
public static void main(String[] args){new Testing().setVisible(true);}
}
This code is functional and I get the icon that I want in textfield. Now I already have my jformattedTextField and my label with the icon and tried the following:
jLabel31.setOpaque(true);
jLabel31.setBackground(teste.getBackground());
jLabel31.setPreferredSize(new Dimension(jLabel31.getPreferredSize().width,teste.getPreferredSize().height));
so the image does not appear in my 'test' textField. Any suggestions?
Update1:
public ConfEmpresa() throws SQLException {
...
Testing1 teste = new Testing1();
teste.setVisible(true);
}
class Testing1 extends JFrame implements MouseListener {
public Testing1() {
JPanel jp = new JPanel();
//Border border = BorderFactory.createLineBorder(Color.GRAY, 1);
//jp.setBorder(border);
//jp.setBackground(Color.WHITE);
jp.addMouseListener(this);
//nomeC = new JTextField(10);
nomeC.setEditable(false);
nomeC.setText("sdfasdf");
//nomeC.setBorder(null);
//tf.setBackground(Color.WHITE);
nomeC.addMouseListener(this);
JLabel lb = new JLabel(new ImageIcon("LogoIcon.png"));
lb.addMouseListener(this);
//jp.add(nomeC);
jp.add(lb);
jPanel3.add(jp);
pack();
}
The mouseclicked part is already as I want. Continue to open two windows and the icon does not appear in the field.