Я не думаю, что можно добавить всплывающую подсказку через этот статический метод. Я предлагаю вам создать собственный экземпляр JOptionPane, найти JTextField и установить его всплывающую подсказку.
public class Main {
public static List<Component> getAllComponents(final Container c) {
Component[] comps = c.getComponents();
List<Component> compList = new ArrayList<Component>();
for (Component comp : comps) {
compList.add(comp);
if (comp instanceof Container)
compList.addAll(getAllComponents((Container) comp));
}
return compList;
}
public static void main(String[] args) {
JOptionPane optionPane = new JOptionPane();
optionPane.setMessage("What's your name?");
optionPane.setMessageType(JOptionPane.QUESTION_MESSAGE);
optionPane.setWantsInput(true);
JDialog dialog = optionPane.createDialog("Simple Question");
for (Component c : getAllComponents(dialog)) {
if (c instanceof JTextField) {
c.setToolTipText("I'm a tooltip!");
}
}
dialog.setVisible(true);
dialog.dispose();
}
}
Щелкните правой кнопкой мыши и вставьте работы по умолчанию.
Вы должны добавить 'dialog.dispose()' после 'setVisible', чтобы освободить ресурсы, которые в противном случае сохраняли бы программу навсегда. (: –
Так верно, исправлено. Спасибо :) –