Why does this program's interface disappear to the right? - java

I'm working on a group project with my friends for a school assignment. Unfortunately, one of my group members made this program which was much worse before (I tried to fix most of the main issues). Only problem now is, the program doesn't load all of the text on the right, instead leaving ellipses (...).
I've tried modifying and removing setBounds, setSize, and contentPane, yet all those proved ineffective. I'm fairly new to Java all round, so please do go easy on my inexperience.
public class HomeMenu extends JFrame {
private JPanel contentPane;
private JTextField textField;
public HomeMenu() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(1366, 768);
setBounds(100, 100, 954, 712);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
setBackground(new Color(255, 255, 255));
getContentPane().setLayout(null);
contentPane.setLayout(null);
JPanel panel = new JPanel();
panel.setBackground(Color.BLACK);
panel.setForeground(Color.WHITE);
panel.setBounds(0, 0, 236, 671);
getContentPane().add(panel);
panel.setLayout(null);
JPanel panel_3 = new JPanel();
panel_3.setBounds(44, 5, 1, 1);
panel.add(panel_3);
panel_3.setLayout(null);
JPanel panel_1 = new JPanel();
panel_1.setBackground(new Color(0, 0, 102));
panel_1.setBounds(233, 240, 705, 431);
getContentPane().add(panel_1);
panel_1.setLayout(null);
JPanel panel_6 = new JPanel();
panel_6.setBackground(SystemColor.controlDkShadow);
panel_6.setBounds(307, 235, 285, 164);
panel_1.add(panel_6);
JLabel lblWED = new JLabel("Weddings\r\n");
panel_6.add(lblWED);
lblWED.setForeground(Color.WHITE);
lblWED.setFont(new Font("Sitka Subheading", Font.PLAIN, 23));
lblWED.setBackground(Color.WHITE);
JLabel lblNewLabel_4 = new JLabel("");
panel_6.add(lblNewLabel_4);
lblNewLabel_4.setIcon(new ImageIcon("C:\\Users\\HP\\Downloads\\groupwork_src_index2.jpg"));
JPanel panel_4 = new JPanel();
panel_4.setBackground(SystemColor.controlDkShadow);
panel_4.setBounds(43, 25, 189, 298);
panel_1.add(panel_4);
JLabel lblBirthdayPartiesl = new JLabel("Birthday Partiesl");
panel_4.add(lblBirthdayPartiesl);
lblBirthdayPartiesl.setFont(new Font("Snap ITC", Font.PLAIN, 18));
lblBirthdayPartiesl.setForeground(Color.WHITE);
lblBirthdayPartiesl.setBackground(Color.WHITE);
JLabel lblNewLabel_3 = new JLabel("");
panel_4.add(lblNewLabel_3);
lblNewLabel_3.setIcon(new ImageIcon("C:\\Users\\HP\\Downloads\\groupwork_src_index.jpg"));
JLabel lblWeDoIt = new JLabel("WE DO nothing at ALL !");
lblWeDoIt.setBounds(68, 359, 212, 40);
panel_1.add(lblWeDoIt);
lblWeDoIt.setForeground(Color.WHITE);
lblWeDoIt.setFont(new Font("Tahoma", Font.PLAIN, 28));
lblWeDoIt.setBackground(Color.WHITE);
JPanel panel_5 = new JPanel();
panel_5.setBounds(297, 25, 358, 185);
panel_1.add(panel_5);
panel_5.setBackground(SystemColor.controlDkShadow);
JLabel lblMeetings = new JLabel("Meetings");
panel_5.add(lblMeetings);
lblMeetings.setForeground(Color.WHITE);
lblMeetings.setFont(new Font("Tahoma", Font.PLAIN, 20));
lblMeetings.setBackground(Color.WHITE);
JLabel lblNewLabel_6 = new JLabel("");
panel_5.add(lblNewLabel_6);
lblNewLabel_6.setIcon(new ImageIcon("C:\\Users\\HP\\Downloads\\groupwork_src_index(1)"));
JLabel lblNewLabel_5 = new JLabel("");
panel_5.add(lblNewLabel_5);
lblNewLabel_5.setIcon(new ImageIcon("C:\\Users\\18060327\\Desktop\\index 3.jpg"));
JPanel panel_2 = new JPanel();
panel_2.setBounds(235, 54, 703, 188);
contentPane.add(panel_2);
panel_2.setBackground(new Color(204, 204, 204));
panel_2.setLayout(null);
JLabel lblNewLabel = new JLabel("ShadEvents");
lblNewLabel.setFont(new Font("Segoe UI Light", Font.PLAIN, 36));
lblNewLabel.setBounds(61, 24, 286, 58);
panel_2.add(lblNewLabel);
JLabel label = new JLabel("Here to make your life harder");
label.setFont(new Font("Segoe UI Light", Font.PLAIN, 13));
label.setBounds(78, 84, 188, 16);
panel_2.add(label);
textField = new JTextField();
textField.setBounds(297, 11, 123, 24);
contentPane.add(textField);
textField.setColumns(10);
JLabel lblNewLabel_2 = new JLabel("");
lblNewLabel_2.setIcon(new ImageIcon("C:\\Users\\HP\\Downloads\\icons8-user-24.png"));
lblNewLabel_2.setBounds(851, 11, 29, 32);
contentPane.add(lblNewLabel_2);
JLabel lblUser = new JLabel("Welcome!"); //fix this user shit //unfixable
lblUser.setBounds(890, 19, 38, 24);
contentPane.add(lblUser);
lblUser.setFont(new Font("Segoe UI Light", Font.PLAIN, 15));
JLabel lblNewLabel_1 = new JLabel();
lblNewLabel_1.setBounds(258, 11, 29, 24);
contentPane.add(lblNewLabel_1);
lblNewLabel_1.setBackground(Color.BLUE);
lblNewLabel_1.setIcon(new ImageIcon("C:\\Users\\HP\\Downloads\\groupwork_src_icons8-search-24.png"));
}
}
Instead of "WE DO nothin..." and "Wel..." (at the top right), it should display "WE DO nothing at ALL!" (Also, do let me know if the code doesn't work.)

Related

Why does my button group doesnt work and display?

I am learning and new to GUI and in this program used ECLIPSE IDE (drag and drop windows builder)
I declared two radio buttons for Gender: Male and Female
If its clicks to male or female button it should only (click one) and go to that button and not both, so therefore I want it automatically the other one to be unselected to avoid duplicate selection
So I already did some research and import javax.swing.ButtonGroup; but I'm still confused as to why it doesn't work because I can still click both of the radio buttons. I think it has something to do with my panel?
Why does it happen and how can I fix it?
Here is my program
public AddRecord() {
setUndecorated(true);
setBackground(Color.WHITE);
setVisible(true);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setBounds(100, 100, 1063, 640);
contentPane = new JPanel();
contentPane.setBounds(new Rectangle(5, 0, 0, 0));
contentPane.setBackground(new Color(255, 255, 240));
contentPane.setBorder(new LineBorder(new Color(0, 0, 28), 1, true));
setLocationRelativeTo(null);
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel pnlInfo = new JPanel();
pnlInfo.setBounds(24, 20, 1015, 597);
contentPane.add(pnlInfo);
pnlInfo.setLayout(null);
JLabel lblGender = new JLabel("Gender:");
lblGender.setBounds(32, 174, 50, 10);
pnlInfo.add(lblGender);
lblGender.setFont(new Font("Tahoma", Font.PLAIN, 11));
ButtonGroup btnBg = new ButtonGroup();
btnBg.add(rdbtnMale);
btnBg.add(rdbtnFemale);
JRadioButton rdbtnMale = new JRadioButton("Male");
rdbtnMale.setBounds(79, 169, 55, 21);
pnlInfo.add(rdbtnMale);
JRadioButton rdbtnFemale = new JRadioButton("Female");
rdbtnFemale.setBounds(136, 169, 76, 21);
pnlInfo.add(rdbtnFemale);
}
Your code does not even compile,
move the lines
ButtonGroup btnBg = new ButtonGroup();
btnBg.add(rdbtnMale);
btnBg.add(rdbtnFemale);
to the end of your code
like this
setUndecorated(true);
setBackground(Color.WHITE);
setVisible(true);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setBounds(100, 100, 1063, 640);
JPanel contentPane = new JPanel();
contentPane.setBounds(new Rectangle(5, 0, 0, 0));
contentPane.setBackground(new Color(255, 255, 240));
contentPane.setBorder(new LineBorder(new Color(0, 0, 28), 1, true));
setLocationRelativeTo(null);
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel pnlInfo = new JPanel();
pnlInfo.setBounds(24, 20, 1015, 597);
contentPane.add(pnlInfo);
pnlInfo.setLayout(null);
JLabel lblGender = new JLabel("Gender:");
lblGender.setBounds(32, 174, 50, 10);
pnlInfo.add(lblGender);
lblGender.setFont(new Font("Tahoma", Font.PLAIN, 11));
JRadioButton rdbtnMale = new JRadioButton("Male");
rdbtnMale.setBounds(79, 169, 55, 21);
pnlInfo.add(rdbtnMale);
JRadioButton rdbtnFemale = new JRadioButton("Female");
rdbtnFemale.setBounds(136, 169, 76, 21);
pnlInfo.add(rdbtnFemale);
ButtonGroup btnBg = new ButtonGroup();
btnBg.add(rdbtnMale);
btnBg.add(rdbtnFemale);

I couldnt set location of components in Java for usinf JFrame and contentPane?

I want to create a simple profile information page with JFrame and contentPane. I added all the components correctly. But I cant set their location. How can i set it? I used setBoundary() method bur it doesnt work.
My Anket.java class is:
import java.awt.*;
import javax.swing.*;
public class Anket {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(new Dimension(600, 300));
frame.setTitle("Profile Information");
Container contentPane = frame.getContentPane();
contentPane.setBackground(Color.GRAY);
JRadioButton rdbtnNewRadioButton = new JRadioButton("Age(10-20)");
rdbtnNewRadioButton.setBounds(412, 50, 50, 20);
frame.getContentPane().add(rdbtnNewRadioButton);
JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("Age(21-30)");
rdbtnNewRadioButton.setBounds(412, 20, 50, 20);
frame.getContentPane().add(rdbtnNewRadioButton_1);
JRadioButton rdbtnNewRadioButton_2 = new JRadioButton("Age(31-40)");
rdbtnNewRadioButton.setBounds(412, 30, 50, 20);
frame.getContentPane().add(rdbtnNewRadioButton_2);
JRadioButton rdbtnNewRadioButton_3 = new JRadioButton("Age(41-50)");
rdbtnNewRadioButton.setBounds(412, 40, 50, 20);
frame.getContentPane().add(rdbtnNewRadioButton_3);
JLabel lblNewLabel = new JLabel("PLEASE ENTER YOUR INFORMATION");
lblNewLabel.setBounds(149, 0, 182, 14);
frame.getContentPane().add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Enter Your Name");
lblNewLabel_1.setBounds(127, 25, 86, 14);
frame.getContentPane().add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel("Enter Your Lastname");
lblNewLabel_2.setBounds(272, 25, 100, 14);
frame.getContentPane().add(lblNewLabel_2);
JLabel lblNewLabel_3 = new JLabel("Enter Your Height");
lblNewLabel_3.setBounds(127, 103, 86, 14);
frame.getContentPane().add(lblNewLabel_3);
JTextField textField = new JTextField();
textField.setBounds(216, 100, 86, 20);
frame.getContentPane().add(textField);
textField.setColumns(10);
JTextField textField_1 = new JTextField();
textField_1.setBounds(127, 48, 86, 20);
frame.getContentPane().add(textField_1);
textField_1.setColumns(10);
JTextField textField_2 = new JTextField();
textField_2.setColumns(10);
textField_2.setBounds(412, 48, 86, 20);
frame.getContentPane().add(textField_2);
JLabel lblNewLabel_4 = new JLabel(new ImageIcon("C:/Users/PC/eclipse-workspace/Project/src/Berguzar.jpg"));
lblNewLabel_4.setBounds(10, 21, 100, 85);
frame.getContentPane().add(lblNewLabel_4);
frame.setLayout(new FlowLayout());
frame.setVisible(true);
}
}
The program doesnt have any error. How can i fix this problem?
My output screen is:
output
You should replace
Container contentPane = frame.getContentPane();
contentPane.setBackground(Color.GRAY);
with
JPanel contentPane = new JPanel(null); // The null is important
contentPane.setBackground(Color.GRAY);
frame.setContentPane(contentPane); // each time you change the content pane you need to revalidate the jframe (frame.setVisible(true) also revalidate the jframe so in this case it is not needed to revalidate the jframe)

WindowBuilder Source Code Layout and Database Implementation

Hi I am a newbie java programmer, I am currently creating a java gui application using WindowBuilder within eclipse.
I have the layout that I like however, the source code is all in one class, and I can't seem to navigate through the panels correctly.
A link to the image for how the layout of panels is in WindowBuilder - http://postimg.org/image/xmnm9ilm1/
I was wondering how can I best layout the code, and how best to navigate through the program.
Bear in mind I don't know many techical terms.
Also what is the best way to implement a microsoft access backend database that can be editied within the program for login usernames, passwords and adding and removing items? I have a seperate database class at the moment.
Thank You
Source code of program is shown below
import java.awt.EventQueue;
import java.awt.Toolkit;
import javax.swing.JFrame;
import java.awt.CardLayout;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Color;
import javax.swing.JList;
import javax.swing.Box;
import java.awt.Panel;
import javax.swing.AbstractListModel;
import javax.swing.ListSelectionModel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class UnivEPOS {
private JFrame frmUniveposV;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private JTextField textField_4;
private JTextField textField_5;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
UnivEPOS window = new UnivEPOS();
window.frmUniveposV.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public UnivEPOS() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmUniveposV = new JFrame();
frmUniveposV.setTitle("UnivEPOS v1.0");
frmUniveposV.setSize(Toolkit.getDefaultToolkit().getScreenSize());
frmUniveposV.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmUniveposV.getContentPane().setLayout(new CardLayout(0, 0));
JPanel Login = new JPanel();
Login.setBackground(new Color(128, 0, 0));
frmUniveposV.getContentPane().add(Login, "name_244778779455709");
Login.setLayout(null);
JLabel lblLogin = new JLabel("LOGIN");
lblLogin.setForeground(new Color(255, 255, 255));
lblLogin.setFont(new Font("Tahoma", Font.BOLD, 18));
lblLogin.setBounds(10, 0, 60, 50);
Login.add(lblLogin);
textField = new JTextField();
textField.setBounds(518, 282, 262, 20);
Login.add(textField);
textField.setColumns(10);
textField_1 = new JTextField();
textField_1.setColumns(10);
textField_1.setBounds(518, 319, 262, 20);
Login.add(textField_1);
JLabel lblNewLabel = new JLabel("Username");
lblNewLabel.setForeground(new Color(255, 255, 255));
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 16));
lblNewLabel.setBounds(416, 283, 92, 14);
Login.add(lblNewLabel);
JLabel lblPassword = new JLabel("Password");
lblPassword.setForeground(new Color(255, 255, 255));
lblPassword.setFont(new Font("Tahoma", Font.BOLD, 16));
lblPassword.setBounds(416, 320, 92, 14);
Login.add(lblPassword);
JButton btnNewButton = new JButton("ENTER");
btnNewButton.addMouseListener(new MouseAdapter() {
#Override
public void mouseClicked(MouseEvent arg0) {
}
});
btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 11));
btnNewButton.setBounds(691, 396, 89, 23);
Login.add(btnNewButton);
JButton btnNewButton_1 = new JButton("EXIT");
btnNewButton_1.addMouseListener(new MouseAdapter() {
#Override
public void mouseClicked(MouseEvent e) {
}
});
btnNewButton_1.setFont(new Font("Tahoma", Font.BOLD, 11));
btnNewButton_1.setBounds(518, 396, 89, 23);
Login.add(btnNewButton_1);
JPanel Home = new JPanel();
Home.setBackground(new Color(128, 0, 0));
frmUniveposV.getContentPane().add(Home, "name_244789265918213");
Home.setLayout(null);
JLabel lblCurrentOrders = new JLabel("CURRENT ORDERS");
lblCurrentOrders.setForeground(new Color(255, 255, 255));
lblCurrentOrders.setBounds(535, 0, 346, 31);
lblCurrentOrders.setFont(new Font("Tahoma", Font.BOLD, 35));
Home.add(lblCurrentOrders);
JButton btnNewButton_2 = new JButton("Previous");
btnNewButton_2.setBounds(614, 598, 95, 31);
Home.add(btnNewButton_2);
JButton btnNewButton_3 = new JButton("Next");
btnNewButton_3.setBounds(731, 598, 95, 31);
Home.add(btnNewButton_3);
JButton btnNewButton_6 = new JButton("NEW ORDER");
btnNewButton_6.setBounds(10, 598, 244, 112);
btnNewButton_6.setFont(new Font("Tahoma", Font.BOLD, 18));
Home.add(btnNewButton_6);
JButton btnNewButton_4 = new JButton("Show Paid");
btnNewButton_4.setBounds(614, 632, 95, 31);
Home.add(btnNewButton_4);
JButton btnNewButton_5 = new JButton("Show Unpaid");
btnNewButton_5.setBounds(731, 632, 95, 31);
Home.add(btnNewButton_5);
JButton btnShowAll = new JButton("SHOW ALL");
btnShowAll.setBounds(658, 663, 131, 31);
Home.add(btnShowAll);
JButton btnAdmin = new JButton("ADMIN");
btnAdmin.setBounds(1245, 682, 95, 37);
Home.add(btnAdmin);
JLabel lblCurrentUser = new JLabel("Current User:");
lblCurrentUser.setForeground(new Color(255, 255, 255));
lblCurrentUser.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblCurrentUser.setBounds(1081, 12, 83, 14);
Home.add(lblCurrentUser);
JLabel lblNewLabel_1 = new JLabel("Date & Time:");
lblNewLabel_1.setForeground(new Color(255, 255, 255));
lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblNewLabel_1.setBounds(10, 14, 80, 14);
Home.add(lblNewLabel_1);
JPanel Order = new JPanel();
Order.setBackground(new Color(128, 0, 0));
frmUniveposV.getContentPane().add(Order, "name_244796279334447");
Order.setLayout(null);
JLabel lblOrder = new JLabel("ORDER:");
lblOrder.setForeground(new Color(255, 255, 255));
lblOrder.setFont(new Font("Tahoma", Font.BOLD, 40));
lblOrder.setBounds(10, 11, 166, 43);
Order.add(lblOrder);
JLabel lblDateTime = new JLabel("DATE & TIME:");
lblDateTime.setForeground(new Color(255, 255, 255));
lblDateTime.setFont(new Font("Tahoma", Font.BOLD, 40));
lblDateTime.setBounds(771, 11, 282, 43);
Order.add(lblDateTime);
JLabel lblTable = new JLabel("TABLE:");
lblTable.setForeground(new Color(255, 255, 255));
lblTable.setFont(new Font("Tahoma", Font.BOLD, 40));
lblTable.setBounds(391, 11, 146, 43);
Order.add(lblTable);
Panel panel = new Panel();
panel.setBounds(10, 75, 650, 489);
Order.add(panel);
panel.setLayout(null);
JLabel lblNewLabel_2 = new JLabel("TOTAL:");
lblNewLabel_2.setForeground(new Color(255, 255, 255));
lblNewLabel_2.setFont(new Font("Tahoma", Font.BOLD, 40));
lblNewLabel_2.setBounds(10, 421, 157, 57);
panel.add(lblNewLabel_2);
JLabel lblCurrentOrder = new JLabel("CURRENT ORDER");
lblCurrentOrder.setForeground(new Color(255, 255, 255));
lblCurrentOrder.setBounds(251, 5, 198, 31);
lblCurrentOrder.setFont(new Font("Tahoma", Font.PLAIN, 25));
panel.add(lblCurrentOrder);
Panel panel_1 = new Panel();
panel_1.setBounds(690, 75, 650, 489);
Order.add(panel_1);
panel_1.setLayout(null);
JLabel lblCategories = new JLabel("CATEGORIES");
lblCategories.setForeground(new Color(255, 255, 255));
lblCategories.setFont(new Font("Tahoma", Font.PLAIN, 25));
lblCategories.setBounds(254, 11, 153, 31);
panel_1.add(lblCategories);
JButton btnPrevious = new JButton("PREVIOUS");
btnPrevious.setBounds(462, 455, 89, 23);
panel_1.add(btnPrevious);
JButton btnNext = new JButton("NEXT");
btnNext.setBounds(551, 455, 89, 23);
panel_1.add(btnNext);
JButton btnNewButton_7 = new JButton("SAVE");
btnNewButton_7.setFont(new Font("Tahoma", Font.BOLD, 30));
btnNewButton_7.setBounds(10, 582, 254, 137);
Order.add(btnNewButton_7);
JButton btnSavePay = new JButton("SAVE & PAY");
btnSavePay.setFont(new Font("Tahoma", Font.BOLD, 30));
btnSavePay.setBounds(274, 582, 274, 137);
Order.add(btnSavePay);
JButton btnFinish = new JButton("FINISH");
btnFinish.setFont(new Font("Tahoma", Font.BOLD, 30));
btnFinish.setBounds(558, 582, 253, 137);
Order.add(btnFinish);
JButton button = new JButton("ADMIN");
button.setFont(new Font("Tahoma", Font.BOLD, 11));
button.setBounds(1245, 682, 95, 37);
Order.add(button);
JButton btnExit = new JButton("EXIT");
btnExit.setFont(new Font("Tahoma", Font.BOLD, 11));
btnExit.setBounds(1114, 682, 95, 37);
Order.add(btnExit);
JPanel Reports = new JPanel();
Reports.setBackground(new Color(128, 0, 0));
frmUniveposV.getContentPane().add(Reports, "name_244798869260892");
Reports.setLayout(null);
Panel panel_2 = new Panel();
panel_2.setBounds(0, 180, 1350, 459);
Reports.add(panel_2);
panel_2.setLayout(null);
JLabel lblSales = new JLabel("SALES");
lblSales.setForeground(new Color(255, 255, 255));
lblSales.setFont(new Font("Tahoma", Font.PLAIN, 25));
lblSales.setBounds(600, 0, 78, 52);
panel_2.add(lblSales);
JLabel lblReports = new JLabel("REPORTS");
lblReports.setForeground(new Color(255, 255, 255));
lblReports.setFont(new Font("Tahoma", Font.BOLD, 35));
lblReports.setBounds(556, 0, 174, 52);
Reports.add(lblReports);
JButton btnNewButton_8 = new JButton("SALES");
btnNewButton_8.setFont(new Font("Tahoma", Font.PLAIN, 25));
btnNewButton_8.setBounds(10, 97, 174, 77);
Reports.add(btnNewButton_8);
JButton btnCancellations = new JButton("CANCELLATIONS");
btnCancellations.setFont(new Font("Tahoma", Font.PLAIN, 25));
btnCancellations.setBounds(194, 97, 221, 77);
Reports.add(btnCancellations);
JButton btnItemsSold = new JButton("ITEMS SOLD");
btnItemsSold.setFont(new Font("Tahoma", Font.PLAIN, 25));
btnItemsSold.setBounds(425, 97, 221, 77);
Reports.add(btnItemsSold);
JLabel lblNewLabel_3 = new JLabel("PAGE");
lblNewLabel_3.setForeground(new Color(255, 255, 255));
lblNewLabel_3.setFont(new Font("Tahoma", Font.PLAIN, 40));
lblNewLabel_3.setBounds(610, 645, 106, 74);
Reports.add(lblNewLabel_3);
JButton btnNewButton_9 = new JButton("PREVIOUS");
btnNewButton_9.setFont(new Font("Tahoma", Font.BOLD, 11));
btnNewButton_9.setBounds(860, 645, 163, 74);
Reports.add(btnNewButton_9);
JButton btnNext_1 = new JButton("NEXT");
btnNext_1.setFont(new Font("Tahoma", Font.BOLD, 11));
btnNext_1.setBounds(1025, 645, 164, 74);
Reports.add(btnNext_1);
JButton btnNewButton_10 = new JButton("EXIT");
btnNewButton_10.setFont(new Font("Tahoma", Font.BOLD, 11));
btnNewButton_10.setBounds(1199, 645, 141, 74);
Reports.add(btnNewButton_10);
JPanel Settings = new JPanel();
Settings.setBackground(new Color(128, 0, 0));
frmUniveposV.getContentPane().add(Settings, "name_244813941995636");
Settings.setLayout(null);
JLabel lblNewLabel_4 = new JLabel("SYSTEM SETTINGS");
lblNewLabel_4.setForeground(new Color(255, 255, 255));
lblNewLabel_4.setFont(new Font("Tahoma", Font.BOLD, 35));
lblNewLabel_4.setBounds(500, 0, 339, 54);
Settings.add(lblNewLabel_4);
JList list = new JList();
list.setForeground(new Color(255, 255, 255));
list.setBackground(new Color(128, 0, 0));
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setFont(new Font("Tahoma", Font.PLAIN, 40));
list.setModel(new AbstractListModel() {
String[] values = new String[] {"USER 1", "USER 2", "USER 3", "USER 4", "USER 5"};
public int getSize() {
return values.length;
}
public Object getElementAt(int index) {
return values[index];
}
});
list.setBounds(10, 82, 634, 481);
Settings.add(list);
JButton btnNewButton_11 = new JButton("ADD USER");
btnNewButton_11.setFont(new Font("Tahoma", Font.BOLD, 11));
btnNewButton_11.setBounds(10, 617, 196, 102);
Settings.add(btnNewButton_11);
JButton btnChangeSuperuserPassword = new JButton("CHANGE SUPERUSER PASSWORD");
btnChangeSuperuserPassword.setFont(new Font("Tahoma", Font.BOLD, 11));
btnChangeSuperuserPassword.setBounds(433, 617, 211, 102);
Settings.add(btnChangeSuperuserPassword);
JButton button_1 = new JButton("EXIT");
button_1.setFont(new Font("Tahoma", Font.BOLD, 11));
button_1.setBounds(1245, 682, 95, 37);
Settings.add(button_1);
Panel panel_3 = new Panel();
panel_3.setBounds(650, 84, 690, 479);
Settings.add(panel_3);
panel_3.setLayout(null);
JLabel lblNewLabel_5 = new JLabel("RECEIPT OF SALE");
lblNewLabel_5.setForeground(new Color(255, 255, 255));
lblNewLabel_5.setFont(new Font("Tahoma", Font.PLAIN, 20));
lblNewLabel_5.setBounds(260, 11, 178, 44);
panel_3.add(lblNewLabel_5);
JLabel lblNewLabel_6 = new JLabel("COMPANY");
lblNewLabel_6.setForeground(new Color(255, 255, 255));
lblNewLabel_6.setFont(new Font("Tahoma", Font.PLAIN, 22));
lblNewLabel_6.setBounds(24, 136, 125, 44);
panel_3.add(lblNewLabel_6);
JLabel lblSalesRepresentative = new JLabel("SALES REP");
lblSalesRepresentative.setForeground(new Color(255, 255, 255));
lblSalesRepresentative.setFont(new Font("Tahoma", Font.PLAIN, 22));
lblSalesRepresentative.setBounds(24, 213, 125, 44);
panel_3.add(lblSalesRepresentative);
JLabel lblAddress = new JLabel("ADDRESS");
lblAddress.setForeground(new Color(255, 255, 255));
lblAddress.setFont(new Font("Tahoma", Font.PLAIN, 22));
lblAddress.setBounds(24, 171, 125, 48);
panel_3.add(lblAddress);
JLabel lblMessage = new JLabel("MESSAGE");
lblMessage.setForeground(new Color(255, 255, 255));
lblMessage.setFont(new Font("Tahoma", Font.PLAIN, 22));
lblMessage.setBounds(24, 256, 125, 38);
panel_3.add(lblMessage);
textField_2 = new JTextField();
textField_2.setBounds(154, 151, 404, 26);
panel_3.add(textField_2);
textField_2.setColumns(10);
textField_3 = new JTextField();
textField_3.setColumns(10);
textField_3.setBounds(154, 188, 404, 26);
panel_3.add(textField_3);
textField_4 = new JTextField();
textField_4.setColumns(10);
textField_4.setBounds(154, 228, 404, 26);
panel_3.add(textField_4);
textField_5 = new JTextField();
textField_5.setColumns(10);
textField_5.setBounds(154, 268, 404, 26);
panel_3.add(textField_5);
JPanel Administration = new JPanel();
Administration.setBackground(new Color(128, 0, 0));
frmUniveposV.getContentPane().add(Administration, "name_244816080502214");
Administration.setLayout(null);
JLabel lblNewLabel_7 = new JLabel("ADMINISTRATION");
lblNewLabel_7.setForeground(new Color(255, 255, 255));
lblNewLabel_7.setFont(new Font("Tahoma", Font.BOLD, 35));
lblNewLabel_7.setBounds(506, 0, 335, 43);
Administration.add(lblNewLabel_7);
JLabel lblCategories_1 = new JLabel("CATEGORIES");
lblCategories_1.setForeground(new Color(255, 255, 255));
lblCategories_1.setFont(new Font("Tahoma", Font.PLAIN, 35));
lblCategories_1.setBounds(90, 88, 214, 43);
Administration.add(lblCategories_1);
JLabel lblSubcategories = new JLabel("SUB-CATEGORIES");
lblSubcategories.setForeground(new Color(255, 255, 255));
lblSubcategories.setFont(new Font("Tahoma", Font.PLAIN, 35));
lblSubcategories.setBounds(528, 88, 292, 43);
Administration.add(lblSubcategories);
JLabel label = new JLabel("SUB-CATEGORIES");
label.setForeground(new Color(255, 255, 255));
label.setFont(new Font("Tahoma", Font.PLAIN, 35));
label.setBounds(1008, 88, 292, 43);
Administration.add(label);
JList list_1 = new JList();
list_1.setBounds(55, 142, 292, 404);
Administration.add(list_1);
JList list_2 = new JList();
list_2.setBounds(528, 142, 292, 404);
Administration.add(list_2);
JList list_3 = new JList();
list_3.setBounds(1008, 142, 292, 404);
Administration.add(list_3);
JButton btnAdd = new JButton("ADD");
btnAdd.setBounds(55, 557, 89, 23);
Administration.add(btnAdd);
JButton button_2 = new JButton("ADD");
button_2.setBounds(528, 557, 89, 23);
Administration.add(button_2);
JButton button_3 = new JButton("ADD");
button_3.setBounds(1008, 557, 89, 23);
Administration.add(button_3);
JButton btnRemove = new JButton("REMOVE");
btnRemove.setBounds(258, 557, 89, 23);
Administration.add(btnRemove);
JButton button_4 = new JButton("REMOVE");
button_4.setBounds(731, 557, 89, 23);
Administration.add(button_4);
JButton button_5 = new JButton("REMOVE");
button_5.setBounds(1211, 557, 89, 23);
Administration.add(button_5);
JButton btnReports = new JButton("REPORTS");
btnReports.setFont(new Font("Tahoma", Font.BOLD, 30));
btnReports.setBounds(10, 638, 180, 81);
Administration.add(btnReports);
JButton btnSettings = new JButton("SETTINGS");
btnSettings.setFont(new Font("Tahoma", Font.BOLD, 30));
btnSettings.setBounds(200, 638, 185, 81);
Administration.add(btnSettings);
JButton button_6 = new JButton("EXIT");
button_6.setFont(new Font("Tahoma", Font.BOLD, 11));
button_6.setBounds(1245, 682, 95, 37);
Administration.add(button_6);
}
}
Source code of database class is shown below
import java.awt.event.*;
import java.sql.*;
public class database {
Connection con;
Statement st;
ResultSet rs;
public database()
{
connect();
frame();
}
public void connect()
{
try{
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver);
String db = "jdbc:odbc:db";
con = DriverManager.getConnection(db);
st = con.createStatement();
}
catch(Exception ex){
}
}
public void frame()
{
new UnivEPOS();
}
}

Java Swing GUI Invisible

basically I have a very simple GUI, but for some reason when I run the code the JButtons only appear when I mouse over them, and the JTextField only appear if I click on them. How do I fix this so that they are visible when the program runs? Thanks.
Here is my code:
//JFrame + settings
JFrame frmFormSubmission = new JFrame();
frmFormSubmission.setSize(new Dimension(350, 165));
frmFormSubmission.setTitle("Form Submission - Client");
frmFormSubmission.setLocationRelativeTo(null);
frmFormSubmission.setVisible(true);
frmFormSubmission.setResizable(false);
frmFormSubmission.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//JPanel
JPanel panel = new JPanel();
frmFormSubmission.getContentPane().add(panel, BorderLayout.CENTER);
panel.setLayout(null);
//JLabels
//Name
JLabel lblName = new JLabel("Name:");
lblName.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblName.setBounds(46, 12, 40, 14);
panel.add(lblName);
//Address
JLabel lblAddress = new JLabel("Address:");
lblAddress.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblAddress.setBounds(33, 37, 53, 14);
panel.add(lblAddress);
//Phone
JLabel lblPhone = new JLabel("Phone #:");
lblPhone.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblPhone.setBounds(28, 62, 58, 14);
panel.add(lblPhone);
//Email
JLabel lblEmail = new JLabel("Email:");
lblEmail.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblEmail.setBounds(46, 87, 36, 14);
panel.add(lblEmail);
//JTextFields
//Name
nameField = new JTextField();
nameField.setBounds(93, 11, 137, 20);
panel.add(nameField);
nameField.setColumns(10);
//Address
addressField = new JTextField();
addressField.setColumns(10);
addressField.setBounds(93, 36, 137, 20);
panel.add(addressField);
//Phone
phoneField = new JTextField();
phoneField.setColumns(10);
phoneField.setBounds(93, 61, 137, 20);
panel.add(phoneField);
//Email
emailField = new JTextField();
emailField.setColumns(10);
emailField.setBounds(93, 86, 137, 20);
panel.add(emailField);
//JButtons
//Submit
JButton btnSubmit = new JButton("Submit");
btnSubmit.setBounds(240, 10, 89, 23);
panel.add(btnSubmit);
//Cancel
JButton btnCancel = new JButton("Cancel");
btnCancel.setBounds(240, 44, 89, 23);
panel.add(btnCancel);
//Flush
JButton btnFlush = new JButton("Flush");
btnFlush.setBounds(240, 76, 89, 23);
panel.add(btnFlush);
//Checkbox
JCheckBox chckbxPromotions = new JCheckBox("Email me with new and promotions!");
chckbxPromotions.setBounds(25, 108, 205, 23);
panel.add(chckbxPromotions);
Any help is very much appreciated!
Call frmFormSubmission.setVisible(true); as the last thing you do. setVisible will layout your components so they can be properly drawn. If you add components without laying them out, then you'll have graphical issues.
For more information on what that means, check out the documentation on the validate method.
Also, try
frmFormSubmission.invalidate();
frmFormSubmission.validate();
frmFormSubmission.repaint();
If this still does not work, you can try this:
SwingUtilities.updateComponentTreeUI(frmFormSubmission);

Why all the JTextField and JTextArea are Display Proper But it cant write on that Component?

In following code that component are display properly but we cant write on the JTextField.
public class CurrentOPDDetail extends JInternalFrame
{
JLabel[] line=new JLabel[10];
JLabel[] lbl=new JLabel[33];
JTextField txtName=new JTextField();
JTextField txtAge=new JTextField();
JTextField txtSex=new JTextField();
JTextField txtWeight=new JTextField();
public CurrentOPDDetail(int n)
{
super("OPD Detail Form",false,false);//Title, Resizable, closable
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setSize(screenSize.width-500,650);
setLocation(170,10);
setVisible(true);
setLayout(null);
lbl[0]=new JLabel("NAME");
lbl[1]=new JLabel("AGE");
lbl[2]=new JLabel("SEX");
lbl[3]=new JLabel("WEIGHT");
lbl[4]=new JLabel("HISTORY");
for(int i=0;i<10;i++)
{
line[i]=new JLabel("");
line[i].setBackground(Color.BLACK);
line[i].setOpaque(true);
}
lbl[0].setBounds(1, 5, 40, 25);
txtName.setBounds(41, 5, 200, 25);
lbl[1].setBounds(262, 5, 30, 25);
txtAge.setBounds(293, 5, 50, 25);
lbl[2].setBounds(370, 5, 30, 25);
txtSex.setBounds(400, 5, 50, 25);
lbl[3].setBounds(470, 5, 50, 25);
txtWeight.setBounds(520, 5, 100, 25);
line[0].setBounds(1, 33, screenSize.width-499, 5);
lbl[4].setBounds(1, 40, 150, 25);
add(line[0]);
add(lbl[0]);
add(txtName);
add(lbl[1]);
add(txtAge);
add(lbl[2]);
add(txtSex);
add(lbl[3]);
add(txtWeight);
}
}
Just use JFrame and getContentPane().add().
The text fields of your internal window work fine then:
JFrame frame = new JFrame();
frame.getContentPane().add(new CurrentOPDDetail(5));
frame.setVisible(true);

Categories

Resources