gpt4 book ai didi

java - 如何在 JTextArea 上添加一条在单击或选择时消失的消息?

转载 作者:太空宇宙 更新时间:2023-11-04 11:26:20 26 4
gpt4 key购买 nike

我的问题很简单,但我不知道它是什么

我有一个用java编写的程序,就像这样

enter image description here

我想在 JTextArea 上添加一条短消息,该消息在单击或选择时会消失,就像您登录 facebook 时一样

enter image description here

我想要的 JTextArea 例如是“Startind Date:”下面的那个 JTextArea 称为 textAreaStartindDate

这是我到目前为止的代码。我使用了 netbeans 内置设计选项

public class CreateEventUI extends javax.swing.JFrame {

private static final long serialVersionUID = 7526472295622776147L;

//GUARDAR EVENTOS EM REGISTOEVENTOS

/**
* Creates new form CriarEventoUI
*/
public CreateEventUI() {
super("Create an Event");
setResizable(false);
initComponents();
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setVisible(true);
}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

labelChooseTypeOfEvent = new javax.swing.JLabel();
comboBoxTypeOfEvent = new javax.swing.JComboBox<>();
labelInsertTypeOfData = new javax.swing.JLabel();
labelTitle = new javax.swing.JLabel();
labelDescription = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
textAreaDescription = new javax.swing.JTextArea();
textFieldTitle = new javax.swing.JTextField();
labelStartingDate = new javax.swing.JLabel();
labelStartSubmissionDate = new javax.swing.JLabel();
labelEndDate = new javax.swing.JLabel();
labelEndSubmissionDate = new javax.swing.JLabel();
labelPlace = new javax.swing.JLabel();
textFieldPlace = new javax.swing.JTextField();
buttonConfirm = new javax.swing.JButton();
buttonCancel = new javax.swing.JButton();
textFieldStartingDate = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

labelChooseTypeOfEvent.setText("Choose the type of event");

comboBoxTypeOfEvent.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Congress" , "Exposition"}));

labelInsertTypeOfData.setText("insert the data");

labelTitle.setText("Title");

labelDescription.setText("Description");

textAreaDescription.setColumns(20);
textAreaDescription.setRows(5);
jScrollPane1.setViewportView(textAreaDescription);

labelStartingDate.setText("Starting date:");

labelStartSubmissionDate.setText("starting date for submissions:");

labelEndDate.setText("End date:");

labelEndSubmissionDate.setText("Ending date for submissions:");

labelPlace.setText("place");

buttonConfirm.setText("Confirm");
buttonConfirm.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonConfirmActionPerformed(evt);
}
});

buttonCancel.setText("Cancel");
buttonCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonCancelActionPerformed(evt);
}
});

textFieldStartingDate.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
textFieldStartingDateActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(25, 25, 25)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(labelInsertTypeOfData)
.addGroup(layout.createSequentialGroup()
.addComponent(labelChooseTypeOfEvent)
.addGap(18, 18, 18)
.addComponent(comboBoxTypeOfEvent, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(labelTitle)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(textFieldTitle))
.addComponent(labelDescription)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(labelPlace)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(textFieldPlace)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(labelStartSubmissionDate)
.addComponent(labelStartingDate)
.addComponent(textFieldStartingDate, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(40, 40, 40)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(labelEndDate)
.addComponent(labelEndSubmissionDate)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGap(173, 173, 173)
.addComponent(buttonConfirm)
.addGap(87, 87, 87)
.addComponent(buttonCancel)))))
.addContainerGap(13, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelChooseTypeOfEvent)
.addComponent(comboBoxTypeOfEvent, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(23, 23, 23)
.addComponent(labelInsertTypeOfData)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelTitle)
.addComponent(textFieldTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(labelDescription)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelStartingDate)
.addComponent(labelEndDate))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(52, 52, 52)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelStartSubmissionDate)
.addComponent(labelEndSubmissionDate))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(textFieldStartingDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelPlace)
.addComponent(textFieldPlace, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(buttonConfirm)
.addComponent(buttonCancel))
.addContainerGap(17, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

private void buttonConfirmActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void buttonCancelActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
}

private void textFieldStartingDateActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

// Variables declaration - do not modify
private javax.swing.JButton buttonCancel;
private javax.swing.JButton buttonConfirm;
private javax.swing.JComboBox<String> comboBoxTypeOfEvent;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JLabel labelChooseTypeOfEvent;
private javax.swing.JLabel labelDescription;
private javax.swing.JLabel labelEndDate;
private javax.swing.JLabel labelEndSubmissionDate;
private javax.swing.JLabel labelInsertTypeOfData;
private javax.swing.JLabel labelPlace;
private javax.swing.JLabel labelStartSubmissionDate;
private javax.swing.JLabel labelStartingDate;
private javax.swing.JLabel labelTitle;
private javax.swing.JTextArea textAreaDescription;
private javax.swing.JTextField textFieldPlace;
private javax.swing.JTextField textFieldStartingDate;
private javax.swing.JTextField textFieldTitle;
// End of variables declaration

}

不使用明显的内容

最佳答案

一般来说,您可以使用 ActionListener 或 MouseListener。由于您没有发布任何代码,我们无法准确帮助您。但也许这篇文章有帮助: Onclick for TextField

关于java - 如何在 JTextArea 上添加一条在单击或选择时消失的消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44315289/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com