我一直在使用的圖像創建一個按鈕:使用雨雲給圓角JButton的
ImageIcon water = new ImageIcon("button.jpeg");
JButton exceptionButton = new JButton(water);
我希望按鈕有圓角,但我不能這樣做。我聽說過Nimbus。我應該使用它來獲得帶有或不帶圖像的按鈕的圓角?
我一直在使用的圖像創建一個按鈕:使用雨雲給圓角JButton的
ImageIcon water = new ImageIcon("button.jpeg");
JButton exceptionButton = new JButton(water);
我希望按鈕有圓角,但我不能這樣做。我聽說過Nimbus。我應該使用它來獲得帶有或不帶圖像的按鈕的圓角?
試試這個課程,這是一個使用netbeans的簡單方法。
/*
* NewJFrame.java
*
* Created on 3 mars 2014, 10:08
*/
package GUI;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
/**
*
* @author boussarhane
*/
public class NewJFrame extends javax.swing.JFrame {
protected UIManager.LookAndFeelInfo[] m_infos;
String[] LAFNames;
/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
m_infos = UIManager.getInstalledLookAndFeels();
LAFNames = new String[m_infos.length];
for (int i = 0; i < m_infos.length; i++) {
//LAFNames[i] = m_infos[i].getName();
if (m_infos[i].getName().equals("Nimbus")) {
try {
UIManager.setLookAndFeel(m_infos[i].getClassName());
SwingUtilities.updateComponentTreeUI(this);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Acceuil.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(Acceuil.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(Acceuil.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedLookAndFeelException ex) {
Logger.getLogger(Acceuil.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("jButton1");
jButton2.setText("jButton2");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap(315, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(41, 41, 41)
.addComponent(jButton1)
.addGap(18, 18, 18)
.addComponent(jButton2)
.addContainerGap(195, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
// End of variables declaration
}
我正在使用eclipse。我可以使用您在Eclipse中提供的相同代碼嗎? – user2822187
是的,你可以使用它,並且稍後將其更好地轉移到相應的代碼部分,並將其用於日食項目 – MDIT
@ Mehdi Boussarhane: 非常感謝您的幫助。我已經接受你的答案,並upvoted相同:)有沒有一種方法,我可以讓3D看按鈕使用nimbus? – user2822187
入住這裏:http://java-swing-tips.blogspot.in/2008/11/rounded-corner-jbutton.html –
我看到四個最近[問題](http://stackoverflow.com /用戶/ 2822187 /用戶2822187)在同一主題上,但很少更新,沒有回票和不接受。 – trashgod
@trashgod 我知道我沒有得到任何滿意的結果與我得到的答案。 – user2822187