• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JTABLE PROBLEM

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I wrote the following code and am unable to get the table get displayed.Can any one help me to get the table displayed,Please..Kindly spot out the errors.
Thanks a lot
With kind Regds
Satheesh.K

<code>
package examples;
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;
import javax.swing.event.*;
import java.sql.*;
import java.awt.BorderLayout;
import java.awt.Dimension;

public class newSSAService extends JFrame
{
public JMenuBar menuBar;
public JToolBar toolBar;
public JFrame frame;
private JLabel jLabel1;
private JLabel jLabel2;
private JLabel jLabel3;
private JLabel jLabel4;
private JLabel jLabel5;
private JLabel jLabel6;
private JComboBox jComboBox1;
private JComboBox jComboBox2;
private JComboBox jComboBox3;
private JComboBox jComboBox4;
private JComboBox jComboBox5;
private JComboBox jComboBox6;
//private JTable jTable1;
//private JScrollPane jScrollPane1;
public JScrollPane scrollpane;

private JPanel contentPane;
//String[] gen=new String[] {"Reload AllData","Get Latest Data","Reload Calender","Synchronise Planned Data","User Sections","Exit"};
String[] edititems=new String[] {"Today","Current Week","Current Month","Current Quarter","Current Year","Current TimeScale"};
char[] editshortcuts={'D','W','M','Q','Y','U'};
//from table examples
private boolean DEBUG=true;
private int rows=10,cols=10;
private String url="jdbc dbc:sadsn";
private Connection con=null;
private Statement stmt;
private JButton Read,Close;
private String[] colnames={"Service Order","Configuration","Configuration Description","Preferred Engineer","Location","Address","City","Status"};
private Object[][] data=new Object[rows][cols];
public JTable table;
//stopped here...
public newSSAService()
{
super("SSA Service Scheduler");
initializeComponent();
this.setVisible(true);
}

private void initializeComponent()
{
jLabel1 = new JLabel();
jLabel2 = new JLabel();
jLabel3 = new JLabel();
jLabel4 = new JLabel();
jLabel5 = new JLabel();
jLabel6 = new JLabel();
jComboBox1 = new JComboBox();
jComboBox2 = new JComboBox();
jComboBox3 = new JComboBox();
jComboBox4 = new JComboBox();
jComboBox5 = new JComboBox();
jComboBox6 = new JComboBox();
frame=new JFrame();
//Included here
JMenuBar menuBar = new JMenuBar();
JMenu general = new JMenu("General");
menuBar.add(general);
ActionListener printListener=new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
System.out.println("Menu Item ["+event.getActionCommand()+"] was pressed");
}
};
JMenuItem useritem;
JMenu NewView=new JMenu("New View");
NewView.add(useritem=new JMenuItem("Service Order By Engineers"));
NewView.add(useritem=new JMenuItem("Service Order By Configuration"));
NewView.add(useritem=new JMenuItem("Activities By Engineer"));
NewView.add(useritem=new JMenuItem("Activities By Objects"));
NewView.add(useritem=new JMenuItem("Planned Activities By Configuration"));
NewView.add(useritem=new JMenuItem("Planned Activities By Objects"));
useritem.addActionListener(printListener);
general.add(NewView);

//general.add("New View");
general.add("Record All Data");
general.add("Get Latest Data");
general.add("Record Calendar");
general.add("Synchronise Planning Data");
JMenuItem userset;
JMenu User=new JMenu("User Settings");
User.add(userset=new JMenuItem("Modify"));
User.add(useritem=new JMenuItem("Create/Delete"));
User.add(useritem=new JMenuItem("Save"));
User.addActionListener(printListener);
general.add(User);

general.add("Exit");


JMenu actions =new JMenu("Actions");
menuBar.add(actions);
actions.add("Cut");
actions.add("Copy");
actions.add("Paste");
actions.add("Find");
actions.add("Interrupt");
actions.add("Remove Interruption");
actions.add("Appointment");
actions.add("Remove Appointment");
actions.add("Unassigned");
actions.add("Release");
actions.add("Transfer");


JMenu view=new JMenu("View");
menuBar.add(view);
view.add("Service Order By Engineer");
view.add("Service Order By Configuration");
view.add("Activities By Engineer");
view.add("Activities By Objects");
view.add("Planned Activities By Configuration");
view.add("Planned Activities By Objects");
view.add("Activities By Order");

JMenu Timescale=new JMenu("TimeScale");
for(int i=0;i<edititems.length;i++)
{
JMenuItem item=new JMenuItem(edititems[i]);
item.setAccelerator(KeyStroke.getKeyStroke(editshortcuts[i],
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),false));
item.addActionListener(printListener);
Timescale.add(item);
}
menuBar.add(Timescale);


JMenu start=new JMenu("Start");
menuBar.add(start);
start.add("Create/Check/Modify Call");
start.add("Service Order");
start.add("Planned Activities");
JMenuItem planningitem;
JMenu Planning=new JMenu("Planning");
Planning.add(planningitem=new JMenuItem("Global SRP"));
Planning.add(planningitem=new JMenuItem("Detail SRP"));
start.add(Planning);

start.add("Calendars");
start.add("Service Order Activities");
start.add("Order Details");
start.add("Activity");
start.add("Material Requirement Lines");
start.add("Labour Requirement Lines");
start.add("Other Requirement Lines");
start.add("Skills");
start.add("DEM Browser");

JMenuItem serviceitem;
JMenu Service=new JMenu("Service Scheduler Assistant");
Service.add(serviceitem=new JMenuItem("Global Schedule"));
Service.add(serviceitem=new JMenuItem("Global Service Order"));
Service.add(serviceitem=new JMenuItem("Global Activation"));
start.add(Service);

JMenu options=new JMenu("Options");
menuBar.add(options);
options.add("Colors");
//options.add("Color Procedure");
JMenuItem coloritem;
JMenu Colorprocedure=new JMenu("Color Procedure");
Colorprocedure.add(coloritem=new JMenuItem("Status"));
//Colorprocedure.add(coloritem=new JMenuItem("Priority Time Scale"));
JMenuItem subitem;
JMenu submenu=new JMenu("Priority Time Scale");
submenu.add(subitem=new JMenuItem("Planning Start Time"));
submenu.add(subitem=new JMenuItem("Planning Finish Time"));
submenu.add(subitem=new JMenuItem("Latest Finish Time"));
submenu.add(subitem=new JMenuItem("Earliest Start Time"));

Colorprocedure.add(submenu);
options.add(Colorprocedure);
Colorprocedure.add(coloritem=new JMenuItem("Service Type"));

options.add("Capacity Calculator");
options.add("Tool Tips");
options.add("Sort Unassigned View");
options.add("Order Progress");
options.add("OverTime Information");
options.add("Flashing");


JMenu help=new JMenu("Help");
menuBar.add(help);
help.add("Help");
help.add("About SSA Service Scheduler");

//JFrame.setDefaultLookAndFeelDecorated(true);
setJMenuBar(menuBar);
//frame.pack();
//frame.setVisible(true);

toolBar = new JToolBar("Formatting");
toolBar.addSeparator();

//Before this included new
/*String columnNames[] = { "ColorStatus", "Flash", "Service Order","Configuration","Configuration Description"};

// Create some data
String dataValues[][] =
{
{ "blue", "flash", "ORT001" },
{ "AVCONF", "av configuration with warrenty"}
};
*/
//from tableexample.java
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
table=new JTable(data,colnames);
table.setPreferredScrollableViewportSize(new Dimension(900,500));
table.setColumnSelectionAllowed(false);
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

//table.setAutoResizeMode(JTable.)
//cellSelectionEnabled(false);
populateTable();
//finished here..
// OLD Create a new table instance

//jTable1 = new JTable(dataValues,columnNames);..OLD//

//jScrollPane1 = new JScrollPane(table);
//Started again copying here..
if(DEBUG)
{
table.addMouseListener(new MouseAdapter()
{
public void MouseClicked(MouseEvent e)
{
//printDebugData();
}
});
}

JLabel title=new JLabel("Unassigned Queue");
title.setFont(new java.awt.Font("Arial",1,30));
title.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
add("North",title);

scrollpane=new JScrollPane(table);
add("Center",scrollpane);

//JPanel buttons=new JPanel();
//Read=new JButton("Read");
//Close=new JButton("Close");
//Read.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent evt) {
// populateTable();
// }
//});
//Close.addActionListener(new ActionListener()
//{
//public void actionPerformed(ActionEvent evt)
//{
//System.out.println("Thanks for using it");
//System.exit(0);

//}
//});
//buttons.add(Read);
//buttons.add(Close);
//add("South",buttons);
}
public void populateTable()
{
String query="SELECT * FROM ServiceOrder";
javax.swing.table.TableModel model=table.getModel();
int r=0;
try
{
con=DriverManager.getConnection(url,"sa","ekb");
stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(query);
while((rs.next()) && (r<rows))
{
Object so=rs.getObject("ServiceOrder");
Object co=rs.getObject("confgn");
Object code=rs.getObject("confgndesc");
Object preengr=rs.getObject("preengr");
Object loc=rs.getObject("Loc");
Object addr=rs.getObject("addr");
Object city=rs.getObject("city");
Object status=rs.getObject("status");


model.setValueAt(so,r,0);
model.setValueAt(co,r,1);
model.setValueAt(code,r,2);
model.setValueAt(preengr,r,3);
model.setValueAt(loc,r,4);
model.setValueAt(addr,r,5);
model.setValueAt(city,r,6);
model.setValueAt(status,r,7);

r++;

}
stmt.close();
con.close();
}catch(SQLException e)
{
System.err.println("SQLException"+e.getMessage());
}

//Stopped here copying....

contentPane = (JPanel)this.getContentPane();
//jLabel1
jLabel1.setText("ServiceCentre");
//
// jLabel2
//
jLabel2.setText("ServiceArea");
//
// jLabel4
//
jLabel3.setText("Skills");
jLabel4.setText("AvailableType");
//
// jLabel5
//
jLabel5.setText("From Date");
//
// jLabel6
//
jLabel6.setText("To");
//
// jComboBox1
//
jComboBox1.addItem("Coimbatore");
jComboBox1.addItem("Chennai");
jComboBox1.addItem("Mumbai");
jComboBox1.addItem("New Delhi");
jComboBox1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jComboBox1_actionPerformed(e);
}

});
//
// jComboBox2
//
jComboBox2.addItem("North Zone");
jComboBox2.addItem("South Zone");
jComboBox2.addItem("Central Zone");
jComboBox2.addItem("Eastern Zone");
jComboBox2.addItem("Western Zone");
jComboBox2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jComboBox2_actionPerformed(e);
}

});
//
// jComboBox3
//
jComboBox3.addItem("Microsoft Components");
jComboBox3.addItem("Java Technologies");
jComboBox3.addItem("ERP");
jComboBox3.addItem("Others");
jComboBox3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jComboBox3_actionPerformed(e);
}

});
//
// jComboBox4
//
jComboBox4.addItem("One");
jComboBox4.addItem("Two");
jComboBox4.addItem("Three");
jComboBox4.addItem("Four");
jComboBox4.addItem("Five");
jComboBox4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jComboBox4_actionPerformed(e);
}

});
//
// jComboBox5
//
jComboBox5.addItem("12/11/2004");
jComboBox5.addItem("13/11/2004");
jComboBox5.addItem("14/11/2004");
jComboBox5.setEditable(true);
jComboBox5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jComboBox5_actionPerformed(e);
}

});
//
// jComboBox6
//
jComboBox6.addItem("12/12/2004");
jComboBox6.addItem("13/12/2004");
jComboBox6.addItem("14/12/2004");
jComboBox6.setEditable(true);
jComboBox6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jComboBox6_actionPerformed(e);
}

});
//
// jTable1
//
table.setModel(new DefaultTableModel(4, 4));
//
// jScrollPane1
//
scrollpane.setViewportView(table);
//jScrollPane1.setViewportView(table);
//
// contentPane
//
contentPane.setLayout(null);
addComponent(contentPane, jLabel1, 2,29,84,18);
addComponent(contentPane, jLabel2, 207,33,76,18);
addComponent(contentPane, jLabel3, 382,32,59,18);
addComponent(contentPane, jLabel4, 2,79,85,18);
addComponent(contentPane, jLabel5, 197,79,84,18);
addComponent(contentPane, jLabel6, 384,80,60,18);
addComponent(contentPane, jComboBox1, 89,32,100,22);
addComponent(contentPane, jComboBox2, 278,32,100,22);
addComponent(contentPane, jComboBox3, 424,30,100,22);
addComponent(contentPane, jComboBox4, 102,76,100,22);
addComponent(contentPane, jComboBox5, 276,79,100,22);
addComponent(contentPane, jComboBox6, 421,78,100,22);
//addComponent(contentPane, jScrollPane1, 33,158,504,170);
addComponent(contentPane, scrollpane, 33,158,504,170);

this.setTitle("SSA Service Scheduler");
this.setLocation(new Point(0, 0));
this.setSize(new Dimension(560, 485));
}

/** Add Component Without a Layout Manager (Absolute Positioning) */
private void addComponent(Container container,Component c,int x,int y,int width,int height)
{
c.setBounds(x,y,width,height);
container.add(c);
}
private void jComboBox1_actionPerformed(ActionEvent e)
{
int index = jComboBox1.getSelectedIndex();
switch(index)
{
case 0: System.out.println("Area Coimbatore Selected "); break;
case 1: System.out.println("Area Chennai selected"); break;
case 2: System.out.println("Mumbai being selected"); break;
case 3: System.out.println("New Delhi being selected"); break;
}
}

private void jComboBox2_actionPerformed(ActionEvent e)
{
int index = jComboBox2.getSelectedIndex();
switch(index)
{
case 0: System.out.println("North Zone Selcted "); break;
case 1: System.out.println("South Zone being selected"); break;
case 2: System.out.println("Central Zone being selected"); break;
case 3: System.out.println("Eastern Zone being selected"); break;
case 4: System.out.println("Western Zone being selected"); break;
}
}

private void jComboBox3_actionPerformed(ActionEvent e)
{
int index = jComboBox3.getSelectedIndex();
switch(index)
{
case 0: System.out.println("Microsoft Components being selected"); break;
case 1: System.out.println("Java Technologies being selected"); break;
case 2: System.out.println("ERP Tehnologies being selected"); break;
case 3: System.out.println("Other's selected"); break;
}
}

private void jComboBox4_actionPerformed(ActionEvent e)
{
int index = jComboBox4.getSelectedIndex();
switch(index)
{
case 0: System.out.println("One selected"); break;
case 1: System.out.println("Two selected"); break;
case 2: System.out.println("Three selected"); break;
case 3: System.out.println("Four selected"); break;
case 4: System.out.println("Five selected"); break;
}
}

private void jComboBox5_actionPerformed(ActionEvent e)
{
int index = jComboBox5.getSelectedIndex();
switch(index)
{
case 0: System.out.println("12/12/2004 being selected"); break;
case 1: System.out.println("13/12/2004 being selected"); break;
case 2: System.out.println("14/12/2004 being selected"); break;
}
}

private void jComboBox6_actionPerformed(ActionEvent e)
{
int index = jComboBox6.getSelectedIndex();
switch(index)
{
case 0: System.out.println("12/11/2004 being selected"); break;
case 1: System.out.println("13/11/2004 being selected"); break;
case 2: System.out.println("14/11/2004 being selected"); break;
}
}
public static void main(String[] args)
{
SSAService ssa=new SSAService();
/*JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame=new JFrame("UnAssigned Queue Values");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(ssa);*/
//JFrame.setDefaultLookAndFeelDecorated(true);
//JDialog.setDefaultLookAndFeelDecorated(true);
//JFrame frame = new JFrame("SSA Service Scheduler");
//frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame.setJMenuBar(ssa.menuBar);
//frame.getContentPane( ).add(ssa.toolBar, BorderLayout.NORTH);
//frame.getContentPane( ).add(ssa.pane, BorderLayout.CENTER);
//frame.pack( );
//frame.setVisible(true);
try
{
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
}
catch (Exception ex)
{
System.out.println("Failed loading L&F: ");
System.out.println(ex);
}
}

}
</code>
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wow, very difficult code to read. you may want to clean that up a bit.

Anyway, after giving it only a few seconds before my eyes crossed, it appears to me that you are trying to use your scrollpane variable before you have actually created it.

In your initialize() method, you call populateTable() before you issue the statement scrollPane = new ScrollPane( table ). However inside of your populateTable() methood, you attempt to use scrollPane.

Clean up the code, and give it another shot.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
So you made a portal in time and started grabbing people. This tiny ad thinks that's rude:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic