2
How to change the date insertion mode in my jTextField
?
Here’s what I got:
I want to insert this icon that is in jLabel
inside my jTextField
. Is this possible?
Upgrade:
import java.awt.*;
import javax.swing.*;
class Testing extends JFrame
{
public Testing()
{
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel p = new JPanel(new BorderLayout());
JTextField tf = new JTextField(5);
JLabel label = new JLabel(new ImageIcon("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 can put the icon I want in the 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));
this way the image does not appear in my textField 'test'. 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.
This icon has some functionality implemented or is just an indication that this is the date field?
– AndersonBS
This icon opens the jcalendar to choose the date.
– Hugo Machado
From a read on that topical
– Danilo Oliveira
https://www.youtube.com/watch?v=RA6don86wq0 Check out this video to see if it helps you, more precisely from minute 3...
– jsantos1991
Thank you both for the tips. Danilooliveira I saw the code you put and it’s functional, now I wanted to adapt it to mine. I’ll edit my question and see if anyone can help me adjust to what I have. jsantos1991 Thanks for the video, no doubt it can help me a lot because the goal is to click on the day, select the date right away, and in jCalendar this seems to me to be more complex to do. Let’s see. Thank you
– Hugo Machado