Results 1 to 7 of 7
  1. #1
    thiram is offline Member
    Join Date
    Sep 2010
    Posts
    4
    Rep Power
    0

    Question SplitButton of dropdownbutton invisible when mouse clicking

    The splitbutton of dropdownbutton is cliked a dropdown menu willbe displayed, but it is not disable when mose cliking operation on the jpanel or outside the window.
    How to invisible or hiding the SplitButton of dropdownbutton menu when performing mouseevent operation on the jpanle or outside the window?
    the code is below of this.

    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_C LOSE);
    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();
    }
    }
    Last edited by thiram; 09-08-2010 at 07:32 AM. Reason: error

  2. #2
    thiram is offline Member
    Join Date
    Sep 2010
    Posts
    4
    Rep Power
    0

    Default

    help me urgently

  3. #3
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    805
    Rep Power
    6

    Default

    we can help.But,check whether the above pasted code is compiling or not.
    Ramya:cool:

  4. #4
    Michael Dunn is offline Member
    Join Date
    Jul 2008
    Posts
    62
    Rep Power
    0

    Default

    > help me urgently

    urgent help = pay for the service = rentacoder.com

  5. #5
    thiram is offline Member
    Join Date
    Sep 2010
    Posts
    4
    Rep Power
    0

    Smile edit code of splitbutton

    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_C LOSE);
    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();
    }
    }

  6. #6
    thiram is offline Member
    Join Date
    Sep 2010
    Posts
    4
    Rep Power
    0

    Default

    The Edit code of splitButton in the below by who is send this code of splitbutton
    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_C LOSE);
    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();
    }
    }

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Invisible component
    By lupo in forum AWT / Swing
    Replies: 3
    Last Post: 04-07-2010, 05:43 PM
  2. opening default browser window in invisible mode
    By robby14 in forum Advanced Java
    Replies: 1
    Last Post: 02-20-2010, 01:50 AM
  3. Mouse Listener for mouse floating over object?
    By Krooger in forum AWT / Swing
    Replies: 1
    Last Post: 11-18-2009, 04:34 AM
  4. Replies: 3
    Last Post: 01-11-2009, 11:20 PM
  5. How to make the JTextArea background invisible
    By bradder in forum AWT / Swing
    Replies: 1
    Last Post: 12-05-2007, 06:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •