So I'm making a group project which is Java console GUI. This is my code for the Java console GUI:
Here's the output from my code.
Why I can't see the title for this output? I already input my title tho. Can somebody fix my layout?
Here's the coding part.
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
public class Homepage5FeatureKeysGUIConsole extends JFrame {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
Homepage5FeatureKeysGUIConsole homePage = new Homepage5FeatureKeysGUIConsole();
homePage.createAndShowGUI();
});
}
public void createAndShowGUI() {
setTitle("Select Feature");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(6, 1, 10, 10));
JButton buttonFeature1 = createFeatureButton("Admin Registration");
panel.add(buttonFeature1);
JButton buttonFeature2 = createFeatureButton("Volunteer Registration");
panel.add(buttonFeature2);
JButton buttonFeature3 = createFeatureButton("Disaster Report");
panel.add(buttonFeature3);
JButton buttonFeature4 = createFeatureButton("Safe Shelter");
panel.add(buttonFeature4);
JButton buttonFeature5 = createFeatureButton("Fund Raising");
panel.add(buttonFeature5);
JButton buttonEmergencyContact = createFeatureButton("Emergency Contact");
panel.add(buttonEmergencyContact);
setContentPane(panel);
pack();
setLocationRelativeTo(null);
setVisible(true);
}
private JButton createFeatureButton(String label) {
JButton button = new JButton(label);
button.setBorderPainted(false);
button.setFocusPainted(false);
button.setBackground(new Color(124, 200, 255));
button.addActionListener((ActionEvent e) -> handleFeatureButton(label));
return button;
}
private void handleFeatureButton(String feature) {
switch (feature) {
case "Admin Registration" -> openAdminAppGUI();
case "Volunteer Registration" -> openVolunteerAppGUI();
case "Disaster Report" -> openDisasterReportGUI();
case "Safe Shelter" -> openSafeShelterGUI();
case "Fund Raising" -> openFundRaisingGUI();
case "Emergency Contact" -> openEmergencyContactGUI();
}
}
private void openAdminAppGUI() {
AdminAppGUI adminAppGUI = new AdminAppGUI();
adminAppGUI.createAndShowGUI();
dispose();
}
private void openVolunteerAppGUI() {
VolunteerAppGUI volunteerAppGUI = new VolunteerAppGUI();
volunteerAppGUI.createAndShowGUI();
dispose();
}
private void openDisasterReportGUI() {
DisasterReportGUI disasterReportGUI = new DisasterReportGUI();
disasterReportGUI.createAndShowGUI();
dispose();
}
private void openSafeShelterGUI() {
SafeShelterGUI safeShelterGUI = new SafeShelterGUI();
safeShelterGUI.createAndShowGUI();
dispose();
}
private void openFundRaisingGUI() {
FundRaisingGUIConsole fundRaisingGUI = new FundRaisingGUIConsole();
fundRaisingGUI.createAndShowGUI();
dispose();
}
private void openEmergencyContactGUI() {
EmergencyContactGUI emergencyContactGUI = new EmergencyContactGUI();
emergencyContactGUI.createAndShowGUI();
dispose();
}
}
I've been trying to fix the layout but it still didn't work at all and I can't see the title from the output which is "Select Feature".
Add manually the dimensions:
panel.setPreferredSize(new Dimension(400, 400));