How to add popup component in JTextField
I want to add component into JTextField as a popup like this.
alt text http://img502.imageshack.us/img502/3688/popupsample.png
i want to add my component for example JPanel..开发者_运维知识库.
You could use a JPopupMenu
-- launched via your button and placed relative to your text field:
final JTextField textField = ...
JButton button = ...
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JPopupMenu popup = new JPopupMenu();
popup.setLayout(new BorderLayout());
popup.add(new JPanel()); // your component
popup.setPopupSize(100, 100);
popup.show(textField, 0, textField.getHeight());
}
});
精彩评论