Consistent look with JideButton and JideSplitButton

This is the forum for JIDE Common Layer which is open sourced at https://github.com/jidesoft/jide-oss. Please note, JIDE technical support doesn't monitor this forum as often as other forums. Please consider subscribe for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Moderator: JIDE Support

Forum rules
Community driven forum for open source JIDE Common Layer. JIDE technical support doesn't monitor this forum as often as other forums. If you only use JIDE Common Layer, please consider subscribing for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Consistent look with JideButton and JideSplitButton

Postby judodan » Mon Sep 17, 2012 12:31 pm

I've got a UI where I am keeping a list of fields to sort by. I use a JideSplitButton to allow the user to add a field to the list (the fields are in the menu) and a JideButton to allow them to remove from the list.

Even though I'm configuring them the same way, they come up looking different (functionality is fine). My code is here:

Code: Select all
       jRemoveSortButton.setText("Remove Sort");
       jRemoveSortButton.setButtonStyle(JideButton.TOOLBOX_STYLE);
       jRemoveSortButton.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent evt) {
               removeSort();
           }
       });

       jAddSortButton.setText("Add Sort...");
       jAddSortButton.setAlwaysDropdown(true);
       jAddSortButton.setButtonStyle(JideSplitButton.TOOLBOX_STYLE);
       for (String field : FIELDS) {
           jAddSortButton.add(new AbstractAction(field) {
               public void actionPerformed(ActionEvent evt) {
                   addSort(evt);
               }
           });
       }


and they come out looking like this:

buttons.png
Button Image
buttons.png (4.84 KiB) Viewed 20700 times


Any suggestions appreciated. Thanks!
judodan
 
Posts: 5
Joined: Thu Sep 13, 2012 9:18 am

Re: Consistent look with JideButton and JideSplitButton

Postby JIDE Support » Mon Sep 17, 2012 2:35 pm

Can you please share with us a stand-alone test case? I tried in Plastic, Metal L&F but could not observe the similar behavior. It looks like that the button is already pressed down when the application is started up.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Consistent look with JideButton and JideSplitButton

Postby judodan » Mon Sep 17, 2012 3:20 pm

Same problem with a simple example. Here is the simple example code:

Code: Select all
package example;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractAction;
import javax.swing.GroupLayout;

import com.jidesoft.swing.JideButton;
import com.jidesoft.swing.JideSplitButton;


public class ButtonSample extends javax.swing.JFrame {

    public ButtonSample() {
        initComponents();
    }

    private void initComponents() {

        jButton1 = new JideButton();
        jButton2 = new JideSplitButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("Button");
        jButton1.setButtonStyle(JideButton.TOOLBOX_STYLE);
        jButton1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                // some code
            }
        });

        jButton2.setText("Split Button...");
        jButton2.setAlwaysDropdown(true);
        jButton2.setButtonStyle(JideSplitButton.TOOLBOX_STYLE);
        jButton2.add(new AbstractAction("Menu Item 1") {
            public void actionPerformed(ActionEvent evt) {
                // handler code...
            }
        });
        jButton2.add(new AbstractAction("Menu Item 2") {
            public void actionPerformed(ActionEvent evt) {
                // handler code...
            }
        });

        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1)
                .addGap(18, 18, 18)
                .addComponent(jButton2)
                .addContainerGap(182, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(45, 45, 45)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap(226, Short.MAX_VALUE))
        );

        pack();
    }

    public static void main(String args[]) {
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ButtonSample.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ButtonSample.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ButtonSample.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ButtonSample.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ButtonSample().setVisible(true);
            }
        });
    }

    private JideButton jButton1;
    private JideSplitButton jButton2;
}

judodan
 
Posts: 5
Joined: Thu Sep 13, 2012 9:18 am

Re: Consistent look with JideButton and JideSplitButton

Postby JIDE Support » Mon Sep 17, 2012 4:01 pm

I believe the different looking is caused by the layout and the focus. The modified test case shows the same appearance for those two kinds of buttons.
Code: Select all
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import com.jidesoft.swing.JideButton;
import com.jidesoft.swing.JideSplitButton;


public class ButtonSample extends javax.swing.JFrame {

    public ButtonSample() {
        initComponents();
    }

    private void initComponents() {

        jButton1 = new JideButton();
        jButton2 = new JideSplitButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("Button");
        jButton1.setButtonStyle(JideButton.TOOLBOX_STYLE);
        jButton1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                // some code
            }
        });

        jButton2.setText("Split Button...");
        jButton2.setAlwaysDropdown(true);
        jButton2.setButtonStyle(JideSplitButton.TOOLBOX_STYLE);
        jButton2.add(new AbstractAction("Menu Item 1") {
            public void actionPerformed(ActionEvent evt) {
                // handler code...
            }
        });
        jButton2.add(new AbstractAction("Menu Item 2") {
            public void actionPerformed(ActionEvent evt) {
                // handler code...
            }
        });

        getContentPane().setLayout(new GridLayout(1, 0));
        getContentPane().add(jButton1);
        getContentPane().add(jButton2);
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                jButton2.requestFocus();
            }
        });

        pack();
    }

    public static void main(String args[]) {
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ButtonSample.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ButtonSample.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ButtonSample.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ButtonSample.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ButtonSample().setVisible(true);
            }
        });
    }

    private JideButton jButton1;
    private JideSplitButton jButton2;
}

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Consistent look with JideButton and JideSplitButton

Postby judodan » Tue Sep 18, 2012 7:38 am

OK, so the suggested layout works better for me too. The problem, though, is that my UI is (of course) much more complicated. I'm sure you can guess from my code that it was generated with NetBeans (I wouldn't hand-code something that complicated :) ).

Is there something to look for/change in my more complex UI? (should I try to post it here?)

Thanks.

Edit:

As a followup, I changed the L&F to be the stock Metal L&F and the buttons look the same now. Seems to be a quirk of the Nimbus theme.
judodan
 
Posts: 5
Joined: Thu Sep 13, 2012 9:18 am

Re: Consistent look with JideButton and JideSplitButton

Postby JIDE Support » Tue Sep 18, 2012 10:14 am

Yep, this is caused by the combination of L&F, layout and focus. You might have to switch the L&F if you don't like to write those UI codes directly.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Consistent look with JideButton and JideSplitButton

Postby Walter Laan » Wed Sep 19, 2012 12:15 am

You can try to call setFocusable(false); on the split button (but cannot use the keyboard then to activate it, so probably want to add a shortcut for it)
Walter Laan
 
Posts: 383
Joined: Mon May 01, 2006 12:13 am


Return to JIDE Common Layer Open Source Project Discussion (Community Driven)

Who is online

Users browsing this forum: Google [Bot] and 9 guests

cron