Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » WindowBuilder » Windowbuilder design tab problem
Windowbuilder design tab problem [message #1722537] Fri, 05 February 2016 14:09 Go to next message
Peter Ream is currently offline Peter ReamFriend
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 #1722550 is a reply to message #1722537] Fri, 05 February 2016 16:17 Go to previous messageGo to next message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3071
Registered: July 2009
Senior Member
Moving this to the WindowBuilder forum.
Re: Windowbuilder design tab problem [message #1784674 is a reply to message #1722550] Mon, 02 April 2018 07:00 Go to previous messageGo to next message
Patrick Moran is currently offline Patrick MoranFriend
Messages: 87
Registered: March 2018
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 #1784675 is a reply to message #1722550] Mon, 02 April 2018 07:01 Go to previous messageGo to next message
Patrick Moran is currently offline Patrick MoranFriend
Messages: 87
Registered: March 2018
Member
I can't see any way of deleting this message, so I'll just remove the misinformation,

[Updated on: Sun, 06 May 2018 22:46]

Report message to a moderator

Re: Windowbuilder design tab problem [message #1784676 is a reply to message #1722550] Mon, 02 April 2018 07:01 Go to previous messageGo to next message
Patrick Moran is currently offline Patrick MoranFriend
Messages: 87
Registered: March 2018
Member
refreshTablet is no longer the right way to do this task. It requires:
void refreshTable(){
return;
}
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("name"));
}
rs.close();
}catch (Exception e) {

JOptionPane.showMessageDialog(null, "Something failed while filling the Combo Box.");
}
refreshTable();
}
Re: Windowbuilder design tab problem [message #1784769 is a reply to message #1784676] Tue, 03 April 2018 19:38 Go to previous messageGo to next message
Patrick Moran is currently offline Patrick MoranFriend
Messages: 87
Registered: March 2018
Member
I've reproduced your problem. My previous notes were wrong.
If you move the refreshTable(); one notch higher, i.e. between the last } and the next-to-the -last } you will get the error messages that made me try my nutty method:
Description Resource Path Location Type
Return type for the method is missing EmployeeInfo.java /Programming Knowledge17+/src line 279 Java Problem
The method refreshTable() is undefined for the type EmployeeInfo EmployeeInfo.java /my bad 17/src line 206 Java Problem
This method requires a body instead of a semicolon EmployeeInfo.java /Programming Knowledge17+/src line 279 Java Problem

Within public class EmployeeInfo extends JFrame {....} it shows no error message, but it boggles the software that treats the design features, somehow.
Within Public EmployeeInfo(){ .....} it gets the above content. I think the computer deals with everything within parentheses but not involving any of the instructions within in curly braces first. Think about what would happen if you inserted it as the first line of EmployeeInfo(){...}.
Maybe the real question is why the part of Eclipse that handles the source does not flag the error when it comes "first" within EmployeeInfo extends JFrame{.....}. The program probably fails because you would be asking to refresh the Tablet before the Tablet has been created.
Re: Windowbuilder design tab problem [message #1786130 is a reply to message #1722537] Wed, 25 April 2018 22:27 Go to previous messageGo to next message
Patrick Moran is currently offline Patrick MoranFriend
Messages: 87
Registered: March 2018
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 #1786393 is a reply to message #1786130] Wed, 02 May 2018 15:33 Go to previous messageGo to next message
Eric Clayberg is currently offline Eric ClaybergFriend
Messages: 979
Registered: July 2009
Location: Boston, MA
Senior Member
What do you mean by "no GUI"?

Are you editing the class using the Java editor or the WindowBuilder editor?
Re: Windowbuilder design tab problem [message #1790646 is a reply to message #1786393] Wed, 13 June 2018 20:27 Go to previous message
Patrick Moran is currently offline Patrick MoranFriend
Messages: 87
Registered: March 2018
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.
Previous Topic:Method setColumnHeader(javax.swing.JViewport) not found in class javax.swing.JPanel
Next Topic:WB not working in Linux and Windows 7 + Photon 4.8.0RC1
Goto Forum:
  


Current Time: Sat Nov 17 16:50:56 GMT 2018

Powered by FUDForum. Page generated in 0.02820 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top