aleem baig

Greenhorn
+ Follow
since Dec 15, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by aleem baig

Thanks for the reply..................
15 years ago
hi i am adding the hard code here as you said....correct me please where I am wrong.
you can directly copy/paste/compile and run....
here is the code....
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import javax.swing.table.*;
import javax.swing.*;
import javax.swing.border.*;
import java.sql.*;
public class ContentPanelDemo extends JPanel implements ActionListener{
private JPanel reportsPanel;
private static JMenuBar menuBar;
private String submenu;
private static JMenu tables,objects,users;
private static JMenuItem m,menuItem,ex1,firstMI,secondMI;
JTabbedPane tabPane;
JTextArea jtAreaOutput,textArea;
JTable jtable;
Vector v=new Vector();
ResultSet rs;
Statement stmt;
Connection con;
public ContentPanelDemo()
{
initFields();
setReportsPanel();
setTabbedPanels();
}
public void initFields() {
try {
menuBar = new JMenuBar();
menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));
objects = new JMenu("Objects");
objects.setMnemonic(KeyEvent.VK_O);
menuBar.add(objects);
firstMI = new JMenuItem("First");
firstMI.addActionListener(this);
objects.add(firstMI);
secondMI = new JMenuItem("second");
secondMI.addActionListener(this);
objects.add(secondMI);
users = new JMenu("Users");
users.setMnemonic(KeyEvent.VK_U);
ex1 = new JMenuItem("Example1");
ex1.addActionListener(this);
users.add(ex1);
menuBar.add(users);
}
catch(Exception e){}
}

public void actionPerformed(ActionEvent event){
JMenuItem source=(JMenuItem)event.getSource();
submenu=source.getText();
JScrollPane jp=null;;
JTextArea area=new JTextArea(5,40);
if(submenu.equalsIgnoreCase("Example1")){
area.setVisible(true);
area.setLineWrap(true);
area.setText("hello");
jp=new JScrollPane(area);
JPanel p=new JPanel();
p.add(jp);
reportsPanel.add(p);
repaint();
}
else
{
PopulationRunnable populationRunnable = new PopulationRunnable();
Thread populationThread = new Thread(populationRunnable);
populationThread.start();
}
}
public void setReportsPanel()
{
reportsPanel = new JPanel();
reportsPanel.setBackground(Color.WHITE);
reportsPanel.setLayout(new BorderLayout());
reportsPanel.add(menuBar,BorderLayout.NORTH);
}
private void setTabbedPanels()
{

tabPane=new JTabbedPane();
tabPane.setBackground(Color.LIGHT_GRAY);
tabPane.setFont(new Font("Arial",Font.PLAIN,18));
tabPane.addTab("Reports",reportsPanel);
add(tabPane);
}

public static void main(String[] args)
{
System.out.println("Building the frame");
JFrame frmFrame = new JFrame();
ContentPanelDemo cPanel = new ContentPanelDemo();
frmFrame.setContentPane(cPanel);
frmFrame.setSize(new Dimension(650, 400));
frmFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmFrame.setVisible(true);
frmFrame.validate();
frmFrame.show();
}
public void windowDeiconified(WindowEvent e) {
repaint();

}
private static void setJMenuBar(JMenuBar menuBar2) {
// TODO Auto-generated method stub
}
private class PopulationRunnable implements Runnable {
public void run() {
JPanel totalGUI = new JPanel();
Vector data=new Vector();
JTable table=null;
String[] title = {"Object Id", "Object Name"};
Vector vtitle=new Vector();
vtitle.addElement("Object Id");
vtitle.addElement("Object Name");
Vector vdata;
Vector cdata=new Vector();
String id=null;
String name=null,type=null;

try{
if(submenu.equalsIgnoreCase("first"))
{
System.out.println("hello");
for(int i=0;i<10;i++)
{
id="id1";
name="name1";
vdata=new Vector();
vdata.addElement(id);
vdata.addElement(name);
data.addElement(vdata);
}
}
else if(submenu.equalsIgnoreCase("second"))
{
for(int i=0;i<15;i++)
{
id="id2";
name="name2";
vdata=new Vector();
vdata.addElement(id);
vdata.addElement(name);
data.addElement(vdata);
}
}
DefaultTableModel model = new DefaultTableModel(data,vtitle){
public boolean isCellEditable(int rowIndex, int colIndex) {
return false; //Disallow the editing of any cell
}
};

table=new JTable(model);
table.setModel(model);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.repaint();
table.revalidate();
System.out.println("size of data vector"+data.size());
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setPreferredSize(new Dimension(600,400));
reportsPanel.add(scrollPane,BorderLayout.CENTER);
reportsPanel.repaint();
reportsPanel.revalidate();
}

catch(Exception e){e.printStackTrace();}

}
}
}

if i select "First" menu item in the above program i am getting 10 rows and if i select "second" menu item then i get 15 rows. but when i click on table or minimize the window i am taking back to the 10 rows which i selected for the first time. please correct me ........
15 years ago
I am sorry if I have made any mistake in posting my problem here. As I am using forums for the first time I am not well versed with the "Do's" and "Dont's". Actually I am keen about my task so asked the people over here to help me out if they can. I know that no one is here to help me in providing the whole code but I gave the code to correct me.
i had overridden isCellEditable() method. still the same problem.....
15 years ago
hi As per Michael Dunn i am sending an example of dynamic generation of tables from our oracle database. please go through the code and tell me where i am wrong.
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import javax.swing.table.*;
import javax.swing.*;
import javax.swing.border.*;
import java.sql.*;
public class ContentPanelDemo extends JPanel implements ActionListener{
private JPanel reportsPanel;
private static JMenuBar menuBar;
private String submenu;
private static JMenu tables,objects,users;
private static JMenuItem m,menuItem,ex1;
JTabbedPane tabPane;
JTextArea jtAreaOutput,textArea;
JTable jtable;
Vector v=new Vector();
ResultSet rs;
Statement stmt;
Connection con;
public ContentPanelDemo()
{
initFields();
setReportsPanel();
setTabbedPanels();
}
public void initFields() {
try {
menuBar = new JMenuBar();
menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));
objects = new JMenu("Objects");
objects.setMnemonic(KeyEvent.VK_O);
menuBar.add(objects);
tables = new JMenu("tab");
objects.add(tables);
getQuery(tables);
users = new JMenu("Users");
users.setMnemonic(KeyEvent.VK_U);
ex1 = new JMenuItem("Example1");
ex1.addActionListener(this);
users.add(ex1);
menuBar.add(users);
}
catch(Exception e){}
}
public void getQuery(JMenu menu)
{ try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc racle:thin:@localhost:1521 rcl","scott","tiger");
Statement stmt=con.createStatement();
System.out.println("connected "+con.getClass());
ResultSet rs=stmt.executeQuery("select * from "+menu.getText());
while(rs.next()){
String name = rs.getString("tname");
m = new JMenuItem(name);
menu.add(m);
m.addActionListener(this);
}
}catch(Exception e){}
}
public void actionPerformed(ActionEvent event){
JMenuItem source=(JMenuItem)event.getSource();
submenu=source.getText();
JScrollPane jp=null;;
JTextArea area=new JTextArea(5,40);
if(submenu.equalsIgnoreCase("Example1")){
area.setVisible(true);
area.setLineWrap(true);
area.setText("hello");
jp=new JScrollPane(area);
JPanel p=new JPanel();
p.add(jp);
reportsPanel.add(p);
repaint();
}
else
{
PopulationRunnable populationRunnable = new PopulationRunnable();
Thread populationThread = new Thread(populationRunnable);
populationThread.start();
}
}
public void setReportsPanel()
{
reportsPanel = new JPanel();
reportsPanel.setBackground(Color.WHITE);
reportsPanel.setLayout(new BorderLayout());
reportsPanel.add(menuBar,BorderLayout.NORTH);
}
private void setTabbedPanels()
{

tabPane=new JTabbedPane();
tabPane.setBackground(Color.LIGHT_GRAY);
tabPane.setFont(new Font("Arial",Font.PLAIN,18));
tabPane.addTab("Reports",reportsPanel);
add(tabPane);
}

public static void main(String[] args)
{ SwingUtilities.invokeLater(new Runnable(){
public void run(){
System.out.println("Building the frame");
JFrame frmFrame = new JFrame();
ContentPanelDemo cPanel = new ContentPanelDemo();
frmFrame.setContentPane(cPanel);
frmFrame.setSize(new Dimension(650, 400));
frmFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmFrame.setVisible(true);
frmFrame.show();
}
});
}
private static void setJMenuBar(JMenuBar menuBar2) {
// TODO Auto-generated method stub

}
private class PopulationRunnable implements Runnable {
public void run() {

JPanel totalGUI = new JPanel();
Vector data=new Vector();
JTable table=null;
String[] title = {"Object Id", "Object Name"};
Vector vtitle=new Vector();
vtitle.addElement("Object Id");
vtitle.addElement("Object Name");
try{

String queryString="select * from "+submenu;
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(queryString);
Vector vdata;
Vector cdata=new Vector();
String id=null;
String name=null,type=null;
while(rs.next()){
id=rs.getString(1);
name=rs.getString(2);
vdata=new Vector();
vdata.addElement(id);
vdata.addElement(name);

data.addElement(vdata);
}
DefaultTableModel model = new DefaultTableModel(data,vtitle);
table=new JTable(model){
public boolean isCellEditable(int rowIndex, int colIndex) {
return false; //Disallow the editing of any cell
}
};
table.setModel(model);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
System.out.println("size of data vector"+data.size());
JScrollPane scrollPane = JTable.createScrollPaneForTable(table);
scrollPane.setPreferredSize(new Dimension(600,400));
reportsPanel.add(scrollPane,BorderLayout.CENTER);
reportsPanel.repaint();
reportsPanel.revalidate();
}
catch(Exception e){e.printStackTrace();}
}
}
}


please provide the oracle class,username and password as per your system settings and run the code. in this code if i get the contents of emp table first then click on dept table then i am able to get the contents of dept table but when i click or scroll the table i am getting the contents of emp table only. this happens if i minimize or shuffle the windows. another thing i would like to know that when i click on Example1 menuitem i should get another panel where i can add some components as per my requirements. hope you understand......
15 years ago
i am using a jtable that is created dynamically based on selection of a menu item in the menubar. i am able to get the table properly. the second time i select a menu item i am able to get the new table correctly but the problem here is whenever i am clicking on the new table data, the table data is changed to old data which i got for the first time. And also whenever i am minimizing the window i am getting only the old data. that is whatever i select for the first time when the application starts is get catched for the whole application.
hope you all understand my problem......i am unable to post the code as it takes some queries which gets dynamical data...
15 years ago
hi i have a jpanel in which i added a menubar and below it i have added some login related components. but when i make use of this panel in another class using jsplitpane my menubar component is displaying beside the login components.its not showing above the components. how to show menubar above the login components in the splitpane.
15 years ago