SplitButton
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Tuesday, September 7, 2010 02:10 AM

SplitButton of Jpopupmenu is how to disable when mouse clicked on the jpanel and outside the window? 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) {    More>>

SplitButton of Jpopupmenu is how to disable when mouse clicked on the jpanel and outside the window?





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();


}

public static void main(String[] args)

{

test();

}

}

   <<Less

Re: SplitButton

Posted By:   kasiram_pusalapati  
Posted On:   Thursday, October 7, 2010 03:30 AM

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();
}
public static void main(String[] args)
{
test();
}
}
About | Sitemap | Contact