File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Custom Button Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Custom Button Problem" Watch "Custom Button Problem" New topic

Custom Button Problem

Kapil Keskar
Ranch Hand

Joined: Dec 04, 2001
Posts: 47
Hello Guys,
I am doing one custom button, which when pressed, a popup menu will be generated.Here Is the code which i have tried. But still got one error of -show()- method which i am unable to understand.
Can anybody tell me this error, Please?

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.plaf.basic.ComboPopup;

public class CustomButton extends JButton
public CustomButton(String str)
JButton jb;
public void init()
//jp=new JPanel();
new JButton();
addActionListener(new Action());
/*this.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent evt)
public static void main(String ar[])
//CustomButton cb=new CustomButton();
JFrame f = new JFrame();
Container c = f.getContentPane();
c.setLayout(new FlowLayout());
c.add(new JLabel("Button :"));
JButton jb = new CustomButton("Example") ;
class Action implements ActionListener, ComboPopup, MouseListener, MouseMotionListener, KeyListener
JPopupMenu popup;
protected JButton button;
public Action()
popup=new JPopupMenu();
JMenuItem mi1=new JMenuItem("One");
JMenuItem mi2=new JMenuItem("Two");
public void actionPerformed(ActionEvent evt)

public void show() {
try {
// if setSelectedItem() was called with a valid date, adjust the calendar
//calendar.setTime( dateFormat.parse( comboBox.getSelectedItem().toString() ) );
} catch (Exception e) {}
public void hide() {
protected JList list = new JList();
public JList getList() {
return list;
public MouseListener getMouseListener() {
return this;
public MouseMotionListener getMouseMotionListener() {
return this;
public KeyListener getKeyListener() {
return this;
public boolean isVisible() {
return popup.isVisible();
public void uninstallingUI() {
// end ComboPopup method implementations
public void mousePressed( MouseEvent e ) {}
public void mouseReleased( MouseEvent e ) {}
// something else registered for MousePressed
public void mouseClicked(MouseEvent e) {
/*if ( !SwingUtilities.isLeftMouseButton(e) )
/*if ( !comboBox.isEnabled() )
if ( comboBox.isEditable() ) {
} else {
protected boolean mouseInside = false;
public void mouseEntered(MouseEvent e) {
mouseInside = true;
public void mouseExited(MouseEvent e) {
mouseInside = false;
// MouseMotionListener
public void mouseDragged(MouseEvent e) {}
public void mouseMoved(MouseEvent e) {}
// KeyListener
public void keyPressed(KeyEvent e) {}
public void keyTyped(KeyEvent e) {}
public void keyReleased( KeyEvent e ) {
if ( e.getKeyCode() == KeyEvent.VK_SPACE ||
e.getKeyCode() == KeyEvent.VK_ENTER ) {

Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Kapil,
Try the following code to see how it can be done.

I agree. Here's the link:
subject: Custom Button Problem
Similar Threads
Calendar Control
Gui button with calendar popup
Problem while working with JPopupMenu
Date/Time Component Required [URGENT]
invoking windows popupmenu from my JFrame[urgent]