SplitButton of dropdownbutton invisible when mouse clicking
click the SplitButton of dropdownbutton, when dropdownmenu willbe displayed. but this is not disabled when mouevent performed on the jpanel
how to disabled or hide the dropdownmenu when we click the dropdown button?
//the code is below
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.plaf.basic.BasicArrowButton;
public class SplitButton1 extends JButton
{
private JButton mainButton, dropDownButton;
private JMenu dropDownMenu;
public SplitButton1()
{
this(" ");
}
public SplitButton1(String text)
{
this(new JButton(text), SwingConstants.SOUTH);
}
public SplitButton1(String text, int orientation)
{
this(new JButton(text), orientation);
}
public SplitButton1(JButton mainButton, int orientation)
{
//super();
this.mainButton = mainButton;
this.dropDownButton = new BasicArrowButton(orientation);
//dropDownButton.addActionListener(this);
this.setBorderPainted(false);
this.dropDownButton.setBorderPainted(false);
this.mainButton.setBorderPainted(false);
this.setPreferredSize(new Dimension(75, 34));
this.setMaximumSize(new Dimension(75, 34));
this.setMinimumSize(new Dimension(200, 34));
this.setLayout(new BorderLayout());
this.setMargin(new Insets(-3, -3,-3,-3));
this.add(mainButton, BorderLayout.CENTER);
this.add(dropDownButton, BorderLayout.EAST);
}
public void setMenu(JMenu menu)
{
this.dropDownMenu = menu;
}
public JButton getMainButton()
{
return mainButton;
}
public JButton getDropDownButton()
{
return dropDownButton;
}
public JMenu getMenu()
{
return dropDownMenu;
}
public static void test()
{
JFrame frame = new JFrame("Simple Split Button Test");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().setLayout(new BorderLayout());
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
JToolBar toolBar = new JToolBar("tb");
JButton sbButton = new JButton(new ImageIcon("D:\\min.png"));
sbButton.setBackground(Color.BLACK);
sbButton.setContentAreaFilled(false);
SplitButton sb = new SplitButton(sbButton, SwingConstants.SOUTH);
//toolBar.add(new JButton("test button"));
toolBar.add(sb);
//p.add(new JLabel("SplitButton test"), BorderLayout.CENTER);
final JPopupMenu testMenu = new JPopupMenu("test menu");
testMenu.add("file");
testMenu.add("new");
sb.setMenu(testMenu);
testMenu.addSeparator();
frame.getContentPane().add(toolBar, BorderLayout.NORTH);
frame.getContentPane().add(p, BorderLayout.CENTER);
frame.setSize(200, 100);
frame.show();
frame.addMouseListener( new MouseAdapter()
{
public void mousePressed(MouseEvent evt)
{
}
} );
}
public static void main(String[] args)
{
test();
}
}
View Answers
Related Tutorials/Questions & Answers:
Advertisements
mouse eventsmouse events
When i click a button i want to retrieve image and audio from database and play it.
how can i do dis. I m using Netbeans IDE and mysql for database.
pls do hel[p me
Mouse ListenerMouse Listener how to move any object with help of
mouse but not drag it in an applet
Mouse MotionMouse Motion Could you please send me the code of finding the (x,y) co-ordinates in a JFrame Compoenent..??
I need it urgently for my project
Image swap on mouse over and mouse moveImage swap on
mouse over and
mouse move i tried the code , sent form u...But if there are 50 images and..i want swap images on mousse over and
mouse out, then the code becomes very lengthy...so please give the code for multiple
Image swap on mouse over and mouse moveImage swap on
mouse over and
mouse move i tried the code , sent form u...But if there are 50 images and..i want swap images on mousse over and
mouse out, then the code becomes very lengthy...so please give the code for multiple
ModuleNotFoundError: No module named 'mouse'ModuleNotFoundError: No module named '
mouse' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
mouse'
How to remove the ModuleNotFoundError: No module named '
mouse'
4D Mouse. Besides these, 4D
mouse has other many advantages like
when user put the cursor...
4D
Mouse
Here...
mouse is an advanced species of traditional 2D
mouse that can move only horizontal
mouse over effects in cssmouse over effects in css I have written a
mouse over effect in CSS. But it is not working in HTML.
Can any one suggest me?
Thanks
Swap images oon mouse over and mouse outSwap images oon
mouse over and
mouse out I have multiple images...i want to swap each image on
mouse out and
mouse over..
<html>
<script language="javascript" type="text/javascript">
if(document.images
Java Swing: Draw rectangle on mouse click has provide an interface
MouseListener.
When the user clicks a
mouse....
In the given example, we are going to draw a rectangle by
clicking the
mouse...Java Swing: Draw rectangle on
mouse click
In this tutorial, you will learn how
Display alert box on clicking linkDisplay alert box on
clicking link
In this tutorial, we will display alert box... a "a href" link. On
clicking
this link ,a alert box prompt message "redirecting...." and
when we click "Ok"
button
ModuleNotFoundError: No module named 'clicking'ModuleNotFoundError: No module named '
clicking' Hi,
My Python... '
clicking'
How to remove the ModuleNotFoundError: No module named '
clicking... to install padas library.
You can install
clicking python with following
mouse event - Java Beginnersmouse event import javax.swing.*;
import java.awr.*;
import...=getContentPane();
setLayout(new FlowLayout());
setTitle("
Mouse Event...");
public MouseEventt()
{
f.setLayout(new FlowLayout());
f.setTitle("
Mouse Retrieve data by clicking a linkRetrieve data by
clicking a link In a page there are 5 links.Every link has a hidden value. According to that hidden value data should be retrieved from the database and data should be displayed in a new page.How to do it?Please
Compose mail by clicking on send mail buttonCompose mail by
clicking on send mail button How i get microsof out look page opend for composing mail by just
clicking on send mail button and
when outlook page open then in to:my email id is written on my jsp page
adding mouse listeners to drop target with adding
mouse listeners to "table" which is drop target, to accept drop component wherever it drops from the
mouse. in this code
when component drops...adding
mouse listeners to drop target import java.awt.*;
import
Handling Mouse Clicks in Java the
mouse click event in the
awt application.
This program simply implements the left click event of the
mouse.
When you
click "Click
Me" button...
Handling
Mouse Clicks in Java
How to design a mouse How to design a
mouse
Follow this example to learn how to design a
mouse.
New File: First take a new file (Ctrl +
N).
Use Pen Tool (P..., point your
mouse pointer then select Direct selection tool (A key) and
adjust
jQuery '.live' & '.die' Mouse eventsjQuery '.live' & '.die'
Mouse events...;
mouse event of jQuery. In this Example, we removes the 'click' event of a
button by
clicking on other button. First button is for enabling event , Second
'append' & 'fade out/in' on mouse hover'append' & 'fade out/in' on
mouse hover
In this tutorial...;
on
mouse hover using jQuery. In this Example, a list is given , if we hover on
first two element, "<<<" is appended on it, to show
mouse Hide text by clicking buttonHide text by
clicking button
In this tutorial, we will discuss about hide/show text by
clicking on button.
In the below example, there are two buttons... button " is used to show text. These actions are
fired
when "
Hide boxes by clicking on it using jQueryHide boxes by
clicking on it using jQuery
In this tutorial , we will discuss about how to hide boxes by
clicking on it
using jQuery. In the given below example , 30 boxes inside web page are
displayed.
When we click on any box (among
Image swap on MouseOver ann Mouse outImage swap on MouseOver ann
Mouse out I tried ur code for multiple images but didnt get the right answer...i dont want the hardcodded code...a code which is flexible with multiple images
<html>
<script language
Explore key & mouse with Flex
Explore key &
mouse with Flex
... to determine for
a key is pressed or not
when an event occurs. In the example...
created. Also two MouseEvent class events click and
mouse over are
used
Display two alert box alternately by clicking on text Display two alert box alternately by
clicking on text
In this tutorial , we will discuss about how to display two alert box
alternately by
clicking on text line. In this example, a text line is given
,
when we click
start tomcat automatically by double clicking on exestart tomcat automatically by double
clicking on exe Hi
I wanted to start tomcat automatically by double
clicking on exe.
i made project in jsp and use tomcat 6 as a server.
but now i wanted to do some challenging in that.
i