Home » Eclipse Projects » WindowBuilder » Windowbuilder design tab problem
Windowbuilder design tab problem [message #1722537] |
Fri, 05 February 2016 14:09 |
Peter Ream Messages: 3 Registered: February 2016 |
Junior Member |
|
|
I am very new to eclipse and java. I am following a youtube video on building an application with WB. My application works as expected. However, I have two statements that are causing eclipse to enter a "not responding state." It must have something to do with these statements placement, but the tutorial works fine. I run with the too calls uncommented and everything works. To
enter design, I comment them. The two problematic method calls are at the very end.
I am running Mac os x 10.11.3 and eclipse mars.
Any ideas?
package org.comany.tutorial;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.EventQueue;
import java.awt.FocusTraversalPolicy;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import net.proteanit.sql.DbUtils;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.Vector;
//import java.sql.PreparedStatement;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.JComboBox;
public class Employeeinfo extends JFrame {
private JPanel contentPane;
private JTable table;
private JComboBox comboBoxName;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Employeeinfo frame = new Employeeinfo();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
Connection connection = null;
private JTextField textFieldEID;
private JTextField textFieldName;
private JTextField textFieldSurname;
private JTextField textFieldAge;
// private MyOwnFocusTraversalPolicy newPolicy;
public void refreshTable()
{
try
{
String query = "select * from EmployeeInfo";
// String query = "select EID, Name, Surname, Age from EmployeeInfo";
PreparedStatement pst = connection.prepareStatement(query);
ResultSet rs = pst.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
rs.close();
pst.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
public void fillComboBox()
{
try
{
String query = "select * from EmployeeInfo";
// String query = "select EID, Name, Surname, Age from EmployeeInfo";
PreparedStatement pst = connection.prepareStatement(query);
ResultSet rs = pst.executeQuery();
while(rs.next())
{
comboBoxName.addItem(rs.getString("Name"));
}
table.setModel(DbUtils.resultSetToTableModel(rs));
rs.close();
pst.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
/**
* Create the frame.
*/
public Employeeinfo()
{
// connect to data base
connection = sqliteConnection.dbConnector();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 655, 418);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton btnLoadTable = new JButton("Load Employee Data");
btnLoadTable.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
String query = "select * from EmployeeInfo";
// String query = "select EID, Name, Surname, Age from EmployeeInfo";
PreparedStatement pst = connection.prepareStatement(query);
ResultSet rs = pst.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
rs.close();
pst.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
});
btnLoadTable.setBounds(392, 48, 206, 29);
contentPane.add(btnLoadTable);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(304, 100, 345, 275);
contentPane.add(scrollPane);
table = new JTable();
scrollPane.setViewportView(table);
// added for grid lines, default is white
table.setGridColor(Color.black);
JLabel lblNewLabel = new JLabel("EID");
lblNewLabel.setBounds(24, 168, 61, 16);
contentPane.add(lblNewLabel);
JLabel lblName = new JLabel("Name");
lblName.setBounds(24, 196, 61, 16);
contentPane.add(lblName);
JLabel lblSurname = new JLabel("Surname");
lblSurname.setBounds(24, 224, 61, 16);
contentPane.add(lblSurname);
JLabel lblAge = new JLabel("Age");
lblAge.setBounds(24, 252, 61, 16);
contentPane.add(lblAge);
textFieldEID = new JTextField();
textFieldEID.setBounds(113, 157, 134, 28);
contentPane.add(textFieldEID);
textFieldEID.setColumns(10);
textFieldName = new JTextField();
textFieldName.setBounds(113, 190, 134, 28);
contentPane.add(textFieldName);
textFieldName.setColumns(10);
textFieldSurname = new JTextField();
textFieldSurname.setBounds(113, 218, 134, 28);
contentPane.add(textFieldSurname);
textFieldSurname.setColumns(10);
textFieldAge = new JTextField();
textFieldAge.setBounds(113, 246, 134, 28);
contentPane.add(textFieldAge);
textFieldAge.setColumns(10);
// Vector<Component> order = new Vector<Component>(5);
// order.add(textFieldEID);
// order.add(textFieldName);
// order.add(textFieldSurname);
// order.add(textFieldAge);
// order.add(table);
// newPolicy = new MyOwnFocusTraversalPolicy(order);
// MyOwnFocusTraversalPolicy newPolicy = new MyOwnFocusTraversalPolicy();
// contentPane.setFocusTraversalPolicy(newPolicy);
JButton btnSave = new JButton("Save");
btnSave.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
try
{
// String query = "select * from EmployeeInfo";
String query = "insert into EmployeeInfo (EID, Name, Surname, Age) values(?, ?, ?, ?)";
PreparedStatement pst = connection.prepareStatement(query);
pst.setString(1, textFieldEID.getText());
pst.setString(2, textFieldName.getText());
pst.setString(3, textFieldSurname.getText());
pst.setString(4, textFieldAge.getText());
pst.execute();
JOptionPane.showMessageDialog(null, "Data saved");
pst.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
refreshTable();
}
});
btnSave.setBounds(64, 292, 117, 29);
contentPane.add(btnSave);
JButton btnUpdate = new JButton("Update");
btnUpdate.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
String query = "update EmployeeInfo set EID='"+textFieldEID.getText()+"' ,name='"+textFieldName.getText()+"',Surname='"+textFieldSurname.getText()+"' ,Age='"+textFieldAge.getText()+"' where EID='"+textFieldEID.getText()+"'";
PreparedStatement pst = connection.prepareStatement(query);
pst.execute();
JOptionPane.showMessageDialog(null, "Data updated");
pst.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
refreshTable();
}
});
btnUpdate.setBounds(64, 325, 117, 29);
contentPane.add(btnUpdate);
JButton btnDelete = new JButton("Delete");
btnDelete.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
String query = "delete from EmployeeInfo where EID='"+textFieldEID.getText()+"' ";
PreparedStatement pst = connection.prepareStatement(query);
pst.execute();
JOptionPane.showMessageDialog(null, "Data deleted");
pst.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
refreshTable();
}
});
btnDelete.setBounds(64, 361, 117, 29);
contentPane.add(btnDelete);
comboBoxName = new JComboBox();
comboBoxName.setBounds(31, 35, 216, 55);
contentPane.add(comboBoxName);
// refreshTable(); // *** This causes error in WB design tab ***
// fillComboBox();
}
}
|
|
| |
Re: Windowbuilder design tab problem [message #1784674 is a reply to message #1722550] |
Mon, 02 April 2018 07:00 |
Patrick Moran Messages: 141 Registered: March 2018 |
Senior Member |
|
|
fillComboBox() will work, but you must supply :
public void fillComboBox()
{
try
{
String query = "select * from EmployeeInfo";
PreparedStatement pst = connection.prepareStatement(query);
ResultSet rs = pst.executeQuery();
while(rs.next())
{
comboBoxName.addItem(rs.getString("EID")); // combobox shows ID numbe.r Using EID works.
//JOptionPane.showMessageDialog(null, comboBoxName); /////21 April
}
table.setModel(DbUtils.resultSetToTableModel(rs)); //restored at 16:36
rs.close(); //restored at 16:36
pst.close(); //restored at 16:36
}
catch (Exception e1)
{
e1.printStackTrace();
}
[
[Updated on: Sun, 06 May 2018 22:43] Report message to a moderator
|
|
| | | |
Re: Windowbuilder design tab problem [message #1786130 is a reply to message #1722537] |
Wed, 25 April 2018 22:27 |
Patrick Moran Messages: 141 Registered: March 2018 |
Senior Member |
|
|
I took this program apart and reassembled it part by part until all that was left is the following lines:
table.setModel(DbUtils.resultSetToTableModel(rs));
table.setModel(DbUtils.resultSetToTableModel(rs));
connect to data base
connection = sqliteConnection.dbConnector();
On line 112 you ned to change Public void Employeeinfo() to something else to avoid duplication. I mistyped and put in public void Empeinfo(). A bit strange but it satisfied Eclipse. There are a few places that may need updated names, but I think this document is accurate and correct as far as it goes.
It compiles all without problems, but there is no GUI. I've noticed that problem before: Things (buttons, labels, etc.)that I have added to source to change/improve the program do not appear on screen.
The only way to get the GUI would seem to be to start all over again, add a label or a button on the GUI image, then go to source and make it like what is in the code that ProgrammingKnowledge put out. That is a long and tedious process. Maybe there is some other software that can take a downloaded abc.java and turn it into a rich GUI interface. I hope so.
I'll attach a file with the sanitized Employeeinformation.java version, for what it's worth. Put things in piece by piece, and frequently view the project in WindowBuilder to make sure that you haven't just put in the poison pill. Leave the commented-out stuff I've listed in that file until after you've got the window right. Save a backup of that java document, uncomment the database stuff, and compile. Then you can risk looking at it with WindowBuilder with the possible result being that infinite loop that crashes Eclipse before it can log any problems that have developed.
|
|
| |
Re: Windowbuilder design tab problem [message #1790646 is a reply to message #1786393] |
Wed, 13 June 2018 20:27 |
Patrick Moran Messages: 141 Registered: March 2018 |
Senior Member |
|
|
Coming back to this question after a long period of frustration.
WindowBuilder is very limited in its ability to take a xyz.java file and produce its graphical elements in its design view. In my experience, anything more than the simplest stuff will not generate a design view.
In the tutorial that Mr. Ream was following, the introduction of a JComboBox component around lesson #15 produces all sorts of opportunities for chaos.
One of the biggest problems that I have noticed, in this particular program, is that if you use the design function to draw a JComboBox on screen, and then give it an action event handler, you can then fill in the requisite code in the source view successfully. For instance:
comboBoxName = new JComboBox();
comboBoxName.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
String query = "select * from STEPS where EID = ? ";
PreparedStatement pst = connection.prepareStatement (query);
pst.setString(1, (String) comboBoxName.getSelectedItem());
ResultSet rs = pst.executeQuery();
while(rs.next())
{
txtEID.setText(rs.getString("EID"));
txtBCKG1.setText(rs.getString("BCKG1"));
txtBCKG2.setText(rs.getString("BCKG2"));
txtBCKG3.setText(rs.getString("BCKG3"));
txtQUES1.setText(rs.getString("QUES1"));
txtQUES2.setText(rs.getString("QUES2"));
txtQUES3.setText(rs.getString("QUES3"));
txtANSW1.setText(rs.getString("ANSW1"));
txtANSW2.setText(rs.getString("ANSW2"));
txtANSW3.setText(rs.getString("ANSW3"));
txtCRIT1.setText(rs.getString("CRIT1"));
txtCRIT2.setText(rs.getString("CRIT2"));
txtCRIT3.setText(rs.getString("CRIT3"));
txtIMAGEID.setText(rs.getString("IMAGEID"));
}
String str = "";
str= txtEID.getText();
JLabel lblSteps = new JLabel(str);
lblSteps.setBounds(383, 134,61, 16);
frame.getContentPane().add(lblSteps);
pst.close();
}
catch(Exception j) {
j.printStackTrace ();
}
}
});
comboBoxName.setBounds(31, 35, 216, 55);
contentPane.add(comboBoxName);
refreshTable();
fillComboBox();
The JComboBox will perform as designed when you run the program. However, if you replace , e.g.,
txtQUES1.setText(rs.getString("QUES1"));
with
txtrQues.setText(rs.getString("Ques"));
because you don't want to awkwardly piece together three JTextFields and understand (falsely) that you can pack those three long lines of text into a single JTextArea and get away with using a jtAREA, then you will likely be in trouble.
I once got a single such replacement to work. I just made a single change like replacing
txtQUES1.setText(rs.getString("QUES1"));
with
txtrQUES1.setText(rs.getString("QUES1"));
(having used the Design function to make a JTextArea visual component).
However, no matter how careful I have been I have never made that experiment work again. In fact, any change in the
comboBoxName = new JComboBox() that tries to use a jtAREA;
will make the combobox fail. At a minimum, the graphical element representing the JComboBox will remain when you view it in design mode, and an empty box will appear when you run the program, but you It will also likely do collateral damage.
I had done a complete rewriting of the ProgrammingKnowledge code, cautiously adding jtAREA items in place of jtFIELD items, compiling and testing to see that even though it wouldn't work without fixing the JCombobox stuff (which I left to last since I suspect that was where the real problem with using jtAREAs must be) at least I was not unintentionally adding any killer code.
When I finally made a new JComboBox (with jtAREAS in it) with provision for the action event as above, I ran it, and the program failed. Then I decided to put in a JOptionPane.showMessageDialog(null, "Problem is: " + j);
at the end of the try-catch stuff for the JComboBox creation after I had done a lot of cautious work of a similar nature.
Stupidly I had not saved enough intermediate steps. When I tried to save and run the program, Eclipse crashed and I lost all the content in the workspace and lost about a week's careful forensic work. All I had changed in the latest "save" was replacing the" j.printStackTrace ()". Stupidly I had assumed that such a minor change would not break the thing it was reporting on. (I went to my TimeMachine to try to go back to the last saved version of the code, but that hard drive was fried. Perhaps it was a coincidence.)
I have used jtAREA fields in other code involving JComboBox stuff, and there has been no problem, but something in the code reproduced above makes it a killer.
|
|
|
Goto Forum:
Current Time: Sat Jan 25 18:38:40 GMT 2025
Powered by FUDForum. Page generated in 0.05310 seconds
|