Issue
I have created a Java app on Netbeans. How can I open a new page by clicking a button, without the page being a popup? I would like it to be like when creating a website with HTML, and pressing a button/link simply redirects to another page.
All of the solutions I read explain how to create a page that pops up.
Edit and clarification:
This is the code I am running (the action taken once the button is pressed).
private void LoginButtonActionPerformed(java.awt.event.ActionEvent evt) {
displays s = new displays();
s.setVisible(true);
Once the Login Button is pressed, a new JFrame opens. Instead, I want the JFrame with the Login Button to show something different, on the same page (once the person is logged in, in this example).
Solution
This little illustration probably does you want. It has a form with a button. Once it is clicked, a textfield on the panel changes.
public class NewJFrame extends javax.swing.JFrame {
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
public NewJFrame() {
initComponents();
}
private void initComponents() {
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jButton1.setText("Click me");
jLabel1.setText("Not yet clicked");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jLabel1.setText("clicked");
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(146, 146, 146)
.addComponent(jButton1))
.addGroup(layout.createSequentialGroup()
.addGap(172, 172, 172)
.addComponent(jLabel1)))
.addContainerGap(160, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(80, 80, 80)
.addComponent(jButton1)
.addGap(78, 78, 78)
.addComponent(jLabel1)
.addContainerGap(102, Short.MAX_VALUE))
);
pack();
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
Answered By - Mr. Wrong