1
I would like to know how to keep updating periodically a Jlabel
, since this label depends on another method. In this case it would be the lblNewLabel_1
.
public class MenuGFinancas extends JFrame {
private JPanel contentPane1;
private String nome;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MenuGFinancas frame = new MenuGFinancas("Teste");
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public MenuGFinancas(String nome) {
ImageIcon image = new ImageIcon("C:\\Users\\admin\\Documents\\Java Project PP\\Imagens\\icone_prestacao_contas.jpg");
setTitle("GFinancas Beta");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 770, 427);
setIconImage(image.getImage());
setResizable(false);
setLocationRelativeTo(null);
contentPane1 = new JPanel();
contentPane1.setForeground(new Color(152, 251, 152));
contentPane1.setOpaque(true);
contentPane1.setBackground(new Color(255, 69, 0));
contentPane1.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane1);
contentPane1.setLayout(null);
setVisible(true);
MenuBar menu = new MenuBar();
menu.setBackground(Color.CYAN);
menu.setBounds(0, 0, 764, 22);
contentPane1.add(menu);
menu.setLayout(new CardLayout(0, 0));
JLabel lblNewLabel = new JLabel("Olá " +nome);
lblNewLabel.setForeground(Color.WHITE);
lblNewLabel.setFont(new Font("Trajan Pro", Font.BOLD, 14));
lblNewLabel.setBounds(0, 22, 764, 34);
contentPane1.add(lblNewLabel);
JLabel lblContaCorrente = new JLabel("Conta Corrente");
lblContaCorrente.setForeground(Color.ORANGE);
lblContaCorrente.setFont(new Font("Tahoma", Font.BOLD, 18));
lblContaCorrente.setBounds(36, 113, 174, 22);
contentPane1.add(lblContaCorrente);
JLabel lblSaldo = new JLabel("Saldo: ");
lblSaldo.setForeground(Color.WHITE);
lblSaldo.setFont(new Font("Tahoma", Font.BOLD, 14));
lblSaldo.setBounds(36, 165, 61, 14);
contentPane1.add(lblSaldo);
MostraSaldo mostraSaldo = new MostraSaldo();
DecimalFormat df = new DecimalFormat("0.00");
String saldo = String.valueOf(df.format(mostraSaldo.PegaSaldo()));
JLabel lblNewLabel_1 = new JLabel(saldo);
lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 14));
lblNewLabel_1.setBounds(107, 165, 68, 14);
contentPane1.add(lblNewLabel_1);
JLabel label = new JLabel("");
label.setBackground(new Color(153, 255, 51));
label.setIcon(new ImageIcon("C:\\Users\\admin\\Documents\\Java Project PP\\Imagens\\back.png"));
label.setBounds(0, 0, 764, 399);
contentPane1.add(label);
setVisible(true);
}
}
No friend, this label receives a value from the Database, I wanted it to update, for example, 15 in 15sec, in case some value is added to the Database, the value appears in this label. I don’t know if I’m talking nonsense, I’m new, but a priori my idea was this.
– Kayque Damasceno
I get it, I guess that answer of utluiz can help.
– Renan Gomes
To update I think it is
lblNewLabel_1.repaint();
– M8n