我尝试过多次使用像CCleaner这样的软件制作带按钮的幻灯片菜单,但我做不到。 这就是我要找的:
带有按钮的幻灯片菜单占据了面板的整个宽度,还有没有边框的按钮和点击的事件来改变背景颜色等等......
这是我的界面应用程序:
我想使用按钮制作相同的幻灯片菜单,例如在名为CCleaner的软件中
源代码:
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
}
谢谢,
答案 0 :(得分:1)
以及没有边框的按钮
如果您不想绘制按钮的边框,则可以使用:
button.setBorderPainted( false );
阅读API,了解您可以控制的按钮的其他属性。