5
It is possible to create JButton
in a "square" format, without the rounded corners when they are already in the JFrame
? Does anyone have an example?
I don’t use any specific laf, but the netbeans default.
The JButtons
is nothing different, are like in the image (I don’t know if it helps much). I tried to take JPanel
, but it doesn’t change anything. There are some events in Jbuttons like mouse clicked, for example. The components are already in Jframe, I use no code for creation, as in the examples cited here.
package view;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
/**
*
* @author Rodrigo
*/
public class Empresa extends javax.swing.JFrame {
/**
* Creates new form Empresa
*/
public Empresa() {
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() {
jPanel5 =
new JPanel(){
public void paintComponent (Graphics g){
Image img =Toolkit.getDefaultToolkit().getImage(
Principal.class.getResource("/images/ws_abstract_gray_bar.png"));
g.drawImage(img, 0,0, this.getWidth(),this.getHeight(),this);
}
};
jLBuscarRegistro = new javax.swing.JLabel();
jTBuscarRegistro = new javax.swing.JTextField();
jBLimpar = new javax.swing.JButton();
jBusacarRegistro = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel5.setBackground(new java.awt.Color(153, 153, 153));
jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder(new java.awt.Color(0, 153, 153), null));
jPanel5.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jLBuscarRegistro.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
jLBuscarRegistro.setForeground(new java.awt.Color(255, 255, 255));
jLBuscarRegistro.setText("Buscar:");
jLBuscarRegistro.setPreferredSize(new java.awt.Dimension(20, 15));
jPanel5.add(jLBuscarRegistro, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, 111, 36));
jTBuscarRegistro.setToolTipText("Insira qualquer infromação ");
jTBuscarRegistro.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 102, 102)));
jPanel5.add(jTBuscarRegistro, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 10, 111, 36));
jBLimpar.setForeground(new java.awt.Color(0, 102, 102));
jBLimpar.setText("Limpar");
jBLimpar.setBorder(null);
jBLimpar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBLimparActionPerformed(evt);
}
});
jPanel5.add(jBLimpar, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 10, 111, 36));
jBusacarRegistro.setForeground(new java.awt.Color(0, 102, 102));
jBusacarRegistro.setIcon(new javax.swing.ImageIcon("D:\\NetBeansProjects\\SGInf\\src\\main\\resources\\images\\help.png")); // NOI18N
jBusacarRegistro.setBorder(null);
jBusacarRegistro.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBusacarRegistroActionPerformed(evt);
}
});
jPanel5.add(jBusacarRegistro, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 10, 111, 36));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 492, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 472, Short.MAX_VALUE)
.addContainerGap()))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(117, 117, 117)
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 65, Short.MAX_VALUE)
.addGap(118, 118, 118)))
);
pack();
}// </editor-fold>
private void jBLimparActionPerformed(java.awt.event.ActionEvent evt) {
jTBuscarRegistro.setText("");
}
private void jBusacarRegistroActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(null, "Insira informações");
}
/**
* @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(Empresa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Empresa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Empresa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Empresa.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 Empresa().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jBLimpar;
private javax.swing.JButton jBusacarRegistro;
private javax.swing.JLabel jLBuscarRegistro;
private javax.swing.JPanel jPanel5;
private javax.swing.JTextField jTBuscarRegistro;
// End of variables declaration
}
Would you be able to show how you’re doing it? Are you using any look and Feel or is the standard (metal)? You need this in some look and Feel specific? Have as you have, but in some cases the "square" button is already standard. Show a mcve so that we can reproduce.
– Bruno César
Hello, thanks for the interest, I edited the question to see if I become clearer.
– Rodrigo
Man, I still don’t understand. The example of this question in Soen generates several buttons in a panel. Is there any way to post the code that generates the screen of this image you included? The buttons must be decorated (or are images), so you need to see the code it generates to help you.
– Bruno César
I understand, follow the form code.
– Rodrigo