简体   繁体   中英

Slide Menu With Buttons

I tried so many times to make Slide Menu With Buttons like in software called CCleaner, but i couldn't. This what i'm looking for :

https://i.stack.imgur.com/6sP2E.png

Slide Menu with buttons takes the full width of panel left, and also the buttons with no border and clicked event to change the background color and so on ...

And this my interface application:

https://i.stack.imgur.com/s2M6Z.png

i want to make the same Slide Menu With Buttons, like in software called CCleaner

the source code :

 public class mainWindow extends javax.swing.JFrame {
/**
 * Creates new form mainWindow
 */
public mainWindow() {
    initComponents();


}


/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

    header = new javax.swing.JPanel();
    Slider = new javax.swing.JPanel();
    jButton1 = new javax.swing.JButton();
    footer = new javax.swing.JPanel();
    main = new javax.swing.JPanel();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    header.setBackground(new java.awt.Color(77, 77, 77));
    header.setPreferredSize(new java.awt.Dimension(673, 50));

    javax.swing.GroupLayout headerLayout = new javax.swing.GroupLayout(header);
    header.setLayout(headerLayout);
    headerLayout.setHorizontalGroup(
        headerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 690, Short.MAX_VALUE)
    );
    headerLayout.setVerticalGroup(
        headerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 50, Short.MAX_VALUE)
    );

    getContentPane().add(header, java.awt.BorderLayout.PAGE_START);

    Slider.setBackground(new java.awt.Color(103, 103, 103));
    Slider.setAlignmentX(0.0F);
    Slider.setAlignmentY(0.0F);
    Slider.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
    Slider.setMinimumSize(new java.awt.Dimension(150, 100));
    Slider.setPreferredSize(new java.awt.Dimension(150, 335));
    Slider.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

    jButton1.setIcon(new javax.swing.ImageIcon("C:\\Users\\AKRAM\\Desktop\\Home-50.png")); // NOI18N
    jButton1.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
    jButton1.setBorderPainted(false);
    jButton1.setFocusPainted(false);
    Slider.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 150, 50));

    getContentPane().add(Slider, java.awt.BorderLayout.LINE_START);

    footer.setBackground(new java.awt.Color(77, 77, 77));
    footer.setMinimumSize(new java.awt.Dimension(50, 50));
    footer.setPreferredSize(new java.awt.Dimension(673, 50));

    javax.swing.GroupLayout footerLayout = new javax.swing.GroupLayout(footer);
    footer.setLayout(footerLayout);
    footerLayout.setHorizontalGroup(
        footerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 690, Short.MAX_VALUE)
    );
    footerLayout.setVerticalGroup(
        footerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 50, Short.MAX_VALUE)
    );

    getContentPane().add(footer, java.awt.BorderLayout.PAGE_END);

    main.setBackground(new java.awt.Color(255, 255, 255));
    main.setMinimumSize(new java.awt.Dimension(100, 50));

    javax.swing.GroupLayout mainLayout = new javax.swing.GroupLayout(main);
    main.setLayout(mainLayout);
    mainLayout.setHorizontalGroup(
        mainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 540, Short.MAX_VALUE)
    );
    mainLayout.setVerticalGroup(
        mainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 391, Short.MAX_VALUE)
    );

    getContentPane().add(main, java.awt.BorderLayout.CENTER);

    pack();
}// </editor-fold>                        

/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    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(mainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(mainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(mainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(mainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new mainWindow().setVisible(true);
        }
    });
}

// Variables declaration - do not modify                     
private javax.swing.JPanel Slider;
private javax.swing.JPanel footer;
private javax.swing.JPanel header;
private javax.swing.JButton jButton1;
private javax.swing.JPanel main;
// End of variables declaration                   
 }

Thank You,

and also the buttons with no border

If you don't want the Border of the button painted then you can use:

button.setBorderPainted( false );

Read the API for other properties of the button that you can control.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM