JAVA HELP: Beans.instantiate, JTable, JBuilder

T

T.R. Diaz

Greetings, I am somewhat experienced in Java programming, but have
just now begun to teach myself Swing. I am currently using JBuilder 9,
and am assembling the GUI using its nice GUI designer. I currently
have JBuilder set to use 'Beans.instantiate' to instantiate the
variuous GUI components. This works for the most part, but I have come
across some oddities using this method:

1: IT seems that you can only call a default constructor using
Beans.instantiate. This seems to severely limit what you can do. For
instance, right now I am trying to populate a JTable object with
information gathered from IBM's RETAIN system. When you call new
JTable, you have the option of constructing a table with predefined
column values. Beans.instantiate makes well.. nothing! I will append
to this post the code of a VERY simple swing application I have
created illustrating this problem. I create the JTable inside a scroll
panel, but when I run the application, nothing appears! I have tried
creating Table models, and trying to add column names that way,, and I
have also tried using the addRow method, but nothing seems to make the
table appear!

What is the purpose of using Beans.instantiate over the new operator,
and why can you only call the default constructor using this method? I
don't understand the usage of something that limits your options.

I've seen various tutorials for JTable on the web, but absolutely none
address the usage of Beans.instantiate at all.

Can anyone help me with this issue? I have seen that JTable is
exceptionally complicated, and I'm sure I just have a conceptual
difficulty understanding the interaction between Beans.instantiate,
JTable, and Table models. Could anyone educate me on these matters? I
really don't understand why the JTable fails to even appear!

Thank you! my email is ryon_day (at) yahoo.com, but I would prefer
public reply so that others may learn from my mistakes :)

Thank you very much!

Ryon Day

----------------Code Follows-----------------

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright &copy; 2003</p>
* @version 1.0
*/

public class TTFrame extends JFrame
{
private JPanel contentPane;
private JMenuBar jMenuBar1 = new JMenuBar();
private JMenu jMenuFile = new JMenu();
private JMenuItem jMenuFileExit = new JMenuItem();
private JMenu jMenuHelp = new JMenu();
private JMenuItem jMenuHelpAbout = new JMenuItem();
private JToolBar jToolBar = new JToolBar();
private JButton jButton1 = new JButton();
private JButton jButton2 = new JButton();
private JButton jButton3 = new JButton();
private ImageIcon image1;
private ImageIcon image2;
private ImageIcon image3;
private JLabel statusBar = new JLabel();
private BorderLayout borderLayout1 = new BorderLayout();
private JPanel jPanel1 = new JPanel();
private BorderLayout borderLayout2 = new BorderLayout();
private JButton jButton4 = new JButton();
private JPanel jPanel2 = new JPanel();
private BorderLayout borderLayout3 = new BorderLayout();
private JScrollPane jScrollPane1 = new JScrollPane();
private JTable jTable1 = new JTable();

//Construct the frame
public TTFrame()
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception
{
image1 = new
ImageIcon(TTFrame.class.getResource("openFile.png"));
image2 = new
ImageIcon(TTFrame.class.getResource("closeFile.png"));
image3 = new ImageIcon(TTFrame.class.getResource("help.png"));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Testing Tables");
statusBar.setText(" ");
jMenuFile.setText("File");
jMenuFileExit.setText("Exit");
jMenuFileExit.addActionListener(new
TTFrame_jMenuFileExit_ActionAdapter(this));
jMenuHelp.setText("Help");
jMenuHelpAbout.setText("About");
jMenuHelpAbout.addActionListener(new
TTFrame_jMenuHelpAbout_ActionAdapter(this));
jButton1.setIcon(image1);
jButton1.setToolTipText("Open File");
jButton2.setIcon(image2);
jButton2.setToolTipText("Close File");
jButton3.setIcon(image3);
jButton3.setToolTipText("Help");
jPanel1.setLayout(borderLayout2);
jButton4.setText("jButton4");
jPanel2.setDebugGraphicsOptions(0);
jPanel2.setLayout(borderLayout3);
jToolBar.add(jButton1);
jToolBar.add(jButton2);
jToolBar.add(jButton3);
jMenuFile.add(jMenuFileExit);
jMenuHelp.add(jMenuHelpAbout);
jMenuBar1.add(jMenuFile);
jMenuBar1.add(jMenuHelp);
this.setJMenuBar(jMenuBar1);
contentPane.add(jToolBar, BorderLayout.NORTH);
contentPane.add(statusBar, BorderLayout.SOUTH);
contentPane.add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jButton4, BorderLayout.NORTH);
jPanel1.add(jPanel2, BorderLayout.CENTER);
jPanel2.add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(jTable1, null);
}
//File | Exit action performed
public void jMenuFileExit_actionPerformed(ActionEvent e)
{
System.exit(0);
}
//Help | About action performed
public void jMenuHelpAbout_actionPerformed(ActionEvent e)
{
TTFrame_AboutBox dlg = new TTFrame_AboutBox(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.pack();
dlg.show();
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING)
{
jMenuFileExit_actionPerformed(null);
}
}
}

class TTFrame_jMenuFileExit_ActionAdapter implements ActionListener
{
private TTFrame adaptee;

TTFrame_jMenuFileExit_ActionAdapter(TTFrame adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.jMenuFileExit_actionPerformed(e);
}
}

class TTFrame_jMenuHelpAbout_ActionAdapter implements ActionListener
{
private TTFrame adaptee;

TTFrame_jMenuHelpAbout_ActionAdapter(TTFrame adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.jMenuHelpAbout_actionPerformed(e);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top