I do so:
package teste;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JRootPane;
import javax.swing.JTextField;
public class Teste extends JFrame {
private JButton fechar, mostrar;
private JTextField campo;
private boolean x;
public Teste() {
final Container tela = getContentPane();
tela.setLayout(null);
this.setResizable(false);
setUndecorated(true);
setBackground(new Color(0f, 0f, 0f, 0f));
this.setTitle("Teste");
this.setBounds(0, 0, 400, 400);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.getContentPane().setLayout(null);
this.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
this.setLocationRelativeTo(null);
fechar = new JButton();
fechar.setBounds(0, 0, 200, 200);
fechar.setText("Fechar");
fechar.setFont(new Font("Arial", Font.BOLD, 12));
fechar.setBackground(new Color(190, 190, 190));
this.add(fechar);
mostrar = new JButton();
mostrar.setBounds(200, 0, 200, 200);
mostrar.setText("Ocultar");
mostrar.setFont(new Font("Arial", Font.BOLD, 12));
mostrar.setBackground(new Color(190, 190, 190));
this.add(mostrar);
campo = new JTextField("Campo de texto");
campo.setBounds(150, 250, 120, 20);
this.add(campo);
mostrar.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mostrar();
}
});
fechar.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
fechar();
}
});
}
public void fechar() {
System.exit(0);
}
public void mostrar() {
if (!x) {
setBackground(new Color(0f, 0f, 0f, 1f));
mostrar.setText("Ocultar");
x = true;
} else {
setBackground(new Color(0f, 0f, 0f, 0f));//Deixa o frame transparente.
mostrar.setText("Mostrar");
x = false;
}
fechar.setOpaque(x);
repaint();
}
}
then my structure is the following, a borderlayout where one the position North of it, then insert a gridlayout and within that grid the Jtextfield, when repaint use in the last grid, nothing happens, when I use in that grid higher my bottom grid disappears all
– tissei
well before I had put this at the end of the
main
and it happened up, now I put right after theadd
and nothing happened, the java asks to change myJPanel
all in the end– tissei
@alleen94 There would be no way you could post a little more of your code in the question so I can test?
– utluiz
I’ll try to get this messy ^^
– tissei