How to put db value in jlist dynamicly? - java

Hi i have a j list where i want to put some database value and want to create jlist automatically but when i try to do this i am not able to achieve this when do i got only one value from database to jlist
how can i achieve this?
here is my code
public class RootSelection1 {
private String connectionURL = "jdbc:mysql://localhost:3306/Trainpis";
private String s1="";
private String s2="";
private final Map<String, ImageIcon> imageMap;
public RootSelection1() {
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(connectionURL, "root", "");
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("Select route,fromr from route");
while(rs.next()){
s1=rs.getString("route");
s2=rs.getString("fromr");
}
} catch(Exception e) {
}
String[] nameList={s1,s2};
imageMap = createImageMap(nameList);
JList list = new JList(nameList);
list.setCellRenderer(new MarioListRenderer());
JScrollPane scroll = new JScrollPane(list);
scroll.setPreferredSize(new Dimension(300, 400));
JFrame frame = new JFrame();
frame.add(scroll);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public class MarioListRenderer extends DefaultListCellRenderer {
Font font = new Font("helvitica", Font.BOLD, 24);
#Override
public Component getListCellRendererComponent(
JList list, Object value, int index,
boolean isSelected, boolean cellHasFocus) {
JLabel label = (JLabel) super.getListCellRendererComponent(
list, value, index, isSelected, cellHasFocus);
label.setVerticalTextPosition(JLabel.TOP);
label.setHorizontalTextPosition(JLabel.CENTER);
label.setBorder(new MatteBorder( 0, 0, 2, 0, Color.GRAY));
label.setIcon(imageMap.get((String) value));
label.setHorizontalTextPosition(JLabel.RIGHT);
label.setFont(font);
return label;
}
}
private Map<String, ImageIcon> createImageMap(String[] list) {
Map<String, ImageIcon> map = new HashMap<>();
for (String s : list) {
map.put(s, new ImageIcon("E:\\SOFTWARE\\TrainPIS\\res\\drawable\\yellow.png"));
}
return map;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new RootSelection1 ();
// ComboboxDemo cb=new ComboboxDemo();
//System.out.println(cb.a);
}
});
}
}
Thanks in advance

You got only one value (one row) because
while(rs.next()){
s1=rs.getString("route");
s2=rs.getString("fromr");
}
has looped already thru the whole record set and s1,s2 hold the values of the last row in the record set.
Try something like this:
List<String> nameList = new ArrayList<String>();
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(connectionURL, "root", "");
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("Select route,fromr from route"
while(rs.next()){
String s1=rs.getString("route");
String s2=rs.getString("fromr");
nameList.add(s1+" "+s2);
}
} catch(Exception e) {
}
JList list = new JList(nameList.toArray());

Related

How to put Names from my database into a JLIst that i have made in another class?

public void GetUsersName(){
try
{
java.sql.Connection con = DriverManager.getConnection(url + dbName, userName, password);
java.sql.Statement s = con.createStatement();
ResultSet result = s.executeQuery("SELECT Username FROM tblcustomers ORDER BY UserID");
if(result != null){
while (result.next())
{
ListUserNames.usersJList.setListData(Username);
}
}
s.close();
con.close();
} catch (SQLException e)
{
System.out.println("Error: " + e);
}
Here my Code from the class where I make my JList Panel , which I then insert to another Class. I cans see my JScrollPane perfectly, the only problem is i can't insert the usernames into it, but I can see other values from a test array for example.
public class ListUserNames extends JPanel{
public static JList<String> usersJList;
public ListUserNames()
{
setLayout(new FlowLayout()) ;
usersJList =new JList<String>();
usersJList.setVisibleRowCount(10) ;
usersJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION) ;
// add a )Scroll Pane containing )List to frame
JScrollPane sp = new JScrollPane(usersJList);
sp.setSize(300, 400);
add(sp);
}
}
JList has no mehtod to add or remove an elment once it's initialized. Instead you can use a ListModel with the JList.
Example:
public class ListUserNames extends JPanel {
public static DefaultListModel<String> listModel = new DefaultListModel<>();
public ListUserNames() {
setLayout(new FlowLayout());
JList<String> usersJList = new JList<String>(listModel);
usersJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// add a )Scroll Pane containing )List to frame
JScrollPane sp = new JScrollPane(usersJList);
sp.setSize(300, 400);
add(sp);
}
}
and your fetch method:
public void getUsersName() throws SQLException {
java.sql.Connection con = DriverManager.getConnection(url + dbName, userName, password);
JList<String> list = new JList<>();
PreparedStatement ps = con.prepareStatement("SELECT Username FROM tblcustomers ORDER BY UserID");
ResultSet result = ps.executeQuery();
DefaultListModel<String> listModel = new DefaultListModel<>();
if (result != null) {
while (result.next())
{
ListUserNames.listModel.addElement(result.getString("Username"));
}
}
ps.close();
con.close();
}
You are using the static aceess to the list. ListUserNames.usersJList.setListData(Username);
That means "usersJList" might have not been initialized yet.
In your can , it was not.
2 solutions.
Solution 1
Initialize "usersJList" in ListUserNames.
such as public static
JList usersJList = new JList();
This is not a recommended way
Solution 2
The second solution make a method to initialize userJList
Code:
GetUsersName.java
public void GetUsersName(){
/*-----your other codes----*/
JList<String> usersJList = ListUserNames.getUsersJList();
if(result != null){
while (result.next())
{
usersJList.setListData(Username);
}
}
/*-----your other codes----*/
}
ListUserNames.java
public class ListUserNames extends JPanel{
private static JList<String> usersJList;
public static JList<String> getUsersJList(){
if (usersJList == null){
usersJList =new JList<String>();
}
return usersJList;
}
public ListUserNames(){
getUsersJList();
setLayout(new FlowLayout()) ;
usersJList.setVisibleRowCount(10) ;
usersJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION) ;
// add a )Scroll Pane containing )List to frame
JScrollPane sp = new JScrollPane(usersJList);
sp.setSize(300, 400);
add(sp);
}
}

Adding JTable and JscrollPane to JPanel on button click

Here what I am doing:
On clicking Search flight, the data comes from Database and display on another JFrame like this:
I want this data to be shown right below the searching panel instead of opening new frame. Something like this:
My codes are as follows:
listingFlight.java
public class listingFlight extends javax.swing.JPanel implements TableCellRenderer {
public listingFlight() {
initComponents();
}
#SuppressWarnings("unchecked")
//Netbeans autogenerated componnent code
#Override
public Component getTableCellRendererComponent(JTable jTable, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
this.jLabel3.setText(jTable.getModel().getValueAt(row, column).toString()+" ("+jTable.getModel().getValueAt(row, column+1).toString()+")");
this.jLabel4.setText(jTable.getModel().getValueAt(row, column+2).toString()+" ("+jTable.getModel().getValueAt(row, column+3).toString()+")");
this.jLabel6.setText(jTable.getModel().getValueAt(row, column+9).toString());
this.jLabel8.setText(jTable.getModel().getValueAt(row, column+6).toString());
this.jLabel11.setText(jTable.getModel().getValueAt(row, column+8).toString());
this.jLabel12.setText(jTable.getModel().getValueAt(row, column+7).toString());
this.jLabel15.setText(jTable.getModel().getValueAt(row, column+4).toString());
this.jLabel16.setText(jTable.getModel().getValueAt(row, column+5).toString());
return this;
}
}
(on clicking button "Search Flight", i m performing this.)
try {
stmt = conn.createStatement();
rs = stmt.executeQuery("select s.airportName,s.cityName,d.airportName,d.cityName,f.srcTime,f.destTime,f.flightNumber,f.availability,f.price,a.airlineName,f.flightID from flights f inner join airlines a on(a.airlineID=f.flightName) inner join cityinfo s on(s.cityID=f.src) inner join cityinfo d on(d.cityID=f.dest) where f.src=" + jComboBox1.getSelectedIndex() + " and f.dest=" + jComboBox2.getSelectedIndex());
while (rs.next()) {
i++;
}
rs.beforeFirst();
data = new Object[i][11];
i = 0;
while (rs.next()) {
data[i][0] = rs.getString(1);
data[i][1] = rs.getString(2);
data[i][2] = rs.getString(3);
data[i][3] = rs.getString(4);
data[i][4] = rs.getString(5);
data[i][5] = rs.getString(6);
data[i][6] = rs.getString(7);
data[i][7] = rs.getString(8);
data[i][8] = rs.getString(9);
data[i][9] = rs.getString(10);
data[i][10] = rs.getString(11);
i++;
}
table = new JTable(data, columnNames) {
#SuppressWarnings("override")
public TableCellRenderer getCellRenderer(int row, int column) {
return new listingFlight();
}
};
showFrame(table);
table.setRowHeight(82);
conn.close();
}
For now showFrame() is :
private void showFrame(JTable table) {
JFrame f = new JFrame("Search Result");
f.setSize(800, 700);
f.add(new JScrollPane(table));
f.setVisible(true);
}
But i m trying to add jScrollPane to existing JPanel instead of creating new JFrame and displaying Data to it
private void showFrame(JTable table) {
this.jPanel1.add(new JScrollPane(table));
}
This showFrame is not adding JScrollPane to my existing jPanel1.

AbstractTabelModel won't show the JTable column names

For some reason my JTable is not displaying it's column names?! I'm certain I've done everything correctly. I've literally copied this from a demonstration so I don't understand why it won't work.
Here is my code:
public class MemTableModel extends AbstractTableModel{
private ArrayList<member> members = new ArrayList<member>();
private String[] columnNames = {"ID", "Name", "Email", "Country", "Genre",
"Gender", "Description", "Type", "Limit", "Card No", "Expiry Date"};
public MemTableModel(){
LoadTableFromDB();
}
public int getRowCount(){
return members.size();
}
public int getColumnCount(){
return columnNames.length;
}
public Object getValueAt(int row, int col){
//Get the row from the about get method
member f = members.get(row);
switch(col){
case 0: return f.getmembId();
case 1: return f.getname();
case 2: return f.getemail();
case 3: return f.getcountry();
case 4: return f.getfavGenre();
case 5: return f.getgender();
case 6: return f.getdescription();
case 7: return f.getmemberType();
case 8: return f.getsongLimit();
case 9: return f.getcard_no();
case 10: return f.getexpiry_date();
}
return null;
}
public String getColumnName(int col){
return columnNames[col];
}
public member getRow(int row){
member c = members.get(row);
return c;
}
public Connection getConnection(){
Connection conDB = null;
/****** DEFAULT MYSQL DRIVERS **************************/
String url = connection.geturl();
String username = connection.getUsername();
String password = connection.getPassword();
try{
//load the MYSQL driver
Class.forName(connection.getDriver());
conDB = DriverManager.getConnection(url, username, password);
}
catch(Exception e){
}
return conDB;
}
//Load all DB values into ARRAY
public void LoadTableFromDB(){
Connection conDB = null;
Statement stmt = null;
ResultSet r = null;
try{
//Connection + Statement
conDB = getConnection();
stmt = conDB.createStatement();
//Queries
String sqlSelectAll = "SELECT * FROM members";
r = stmt.executeQuery(sqlSelectAll);
members.clear();
//Loop through the resultset
while(r.next()){
members.add(new member(r.getInt("membId"), r.getString("name"),
r.getString("email"), r.getString("country"), r.getString("favGenre"),
r.getString("gender"), r.getString("description"), r.getString("memberType"),
r.getString("songLimit"), r.getString("card_no"), r.getString("expiry_date")));
}
conDB.close(); // Close the DB connection
}//End of TRY
catch(Exception er){
System.out.println("Error was: " + er);
}
}
}
Here is how I've implemented the JTable:
public class ViewAll extends JFrame implements ActionListener{
//Jtextfields, buttons, labels
private JButton btnBack = new JButton("Back");
private static JLabel lblMembTitle = new JLabel("<html><h1>All Members</h1></html>");
private static JLabel lblPlayTitle = new JLabel("<html><h1>All Playlists</h1><br /></html>");
//Containers, Panels, Scrollpanes
private Container mainCon = this.getContentPane();
private static JPanel pnlTable = new JPanel(new BorderLayout());
//Jpanels - sections
private JPanel mainPanel = new JPanel();
private JPanel subPanel1 = new JPanel();
private JPanel subPanel2 = new JPanel();
private JPanel subPanel3 = new JPanel();
//Tables
private static JTable tblShowAllMemb = new JTable();
private static JTable tblShowAllPlay = new JTable();
JScrollPane scrollPane = new JScrollPane(mainPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
public ViewAll(){
super("Search/Edit/Delete Members");
this.setBounds(400, 800, 854,400);
this.setVisible(true);
mainCon.add(scrollPane);
//Table Models:
MemTableModel tblMembers = new MemTableModel();
PlayTableModel tblPlaylist = new PlayTableModel();
//LAYOUT
/*By removing this the scrollpane works
^^mainPanel is already added to the scrollPane object above ^^
*/
// mainCon.add(mainPanel);
//Main Panel
mainPanel.setLayout(new BorderLayout());
mainPanel.add(BorderLayout.NORTH, subPanel1);
mainPanel.add(BorderLayout.CENTER, subPanel2);
//Panel1 - Member table + Back Button
subPanel1.setLayout(new BorderLayout());
subPanel1.add(BorderLayout.NORTH, btnBack);
subPanel1.add(BorderLayout.CENTER, lblMembTitle);
subPanel1.add(BorderLayout.SOUTH, tblShowAllMemb);
tblShowAllMemb.setModel(tblMembers);
btnBack.addActionListener(this);
//Panel2 - Playlist table
subPanel2.add(BorderLayout.NORTH, lblPlayTitle);
subPanel2.add(BorderLayout.CENTER, tblShowAllPlay);
tblShowAllPlay.setModel(tblPlaylist);
}
#Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == btnBack){
this.dispose();
}
}
}
The likely issue is you've not wrapped the JTable, which represents your TableModel in a JScrollPane as demonstrated in How to Use Tables
By simply using something like...
add(new JScrollPane(new JTable(new MemTableModel())));
I can get:
See also How to Use Scroll Panes for more details
Updated based on updated code...
Not one of your tables is actually wrapped within it's own JScrollPane
// By the way, static here is very, very bad idea
private static JTable tblShowAllMemb = new JTable();
private static JTable tblShowAllPlay = new JTable();
JScrollPane scrollPane = new JScrollPane(mainPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
public ViewAll(){
//....
//Table Models:
MemTableModel tblMembers = new MemTableModel();
PlayTableModel tblPlaylist = new PlayTableModel();
//...
subPanel1.add(BorderLayout.SOUTH, tblShowAllMemb);
//...
subPanel2.add(BorderLayout.CENTER, tblShowAllPlay);
You've just added the table by itself to some other container. Instead, consider using something like
//...
subPanel1.add(BorderLayout.SOUTH, new JScrollPane(tblShowAllMemb));
//...
subPanel2.add(BorderLayout.CENTER, new JScrollPane(tblShowAllPlay));

update/refresh combobox with glazedlists

how could i ahhm.."auto-update" my comboBox..?im using glazedlists autoComplete and im bit lost on how to do it..ive read some like use eventlists and basiclistbut i couldnt get the idea on how to make it work..
pls help :(
heres my sample code..but i dunno whats next to it..ive tried using eventlists but couldnt make it update on its own..
abc = AutoCompleteSupport.install(comboSearch,GlazedLists.eventListOf(auto));
abc.setStrict(false);
public void count(){
try{
String sql2 = "select count(*) from daily_input";
stmt = conn.prepareStatement(sql2);
rs=stmt.executeQuery();
while(rs.next()){
String x = rs.getString("count(*)");
z = Integer.parseInt(x);
}
auto = new String[z];
idNum = new int[z];
}
catch(SQLException | NumberFormatException e){
}
}
public void cB(){
count();
i=0;
try{
String sql = "Select concat(first_name, ' ',last_name) as full_name from daily_input";
stmt = conn.prepareStatement(sql);
rs=stmt.executeQuery();
while(rs.next()){
String name = rs.getString("full_name");
auto[i] = name;
i++;
}
comboSearch.isEditable();
}
You need to connect your combo-box with event list and then add elements to event list.
public class ComboBoxTest {
private final EventList<String> values;
public ComboBoxTest() {
this.values = GlazedLists.eventListOf("A", "B", "C", "D");
}
public Component createControl() {
JPanel panel = new JPanel(new BorderLayout());
panel.add(this.createComboBox(), BorderLayout.NORTH);
panel.add(new JButton(new AbstractAction("Add Elements") {
#Override
public void actionPerformed(ActionEvent e) {
ComboBoxTest.this.addElements();
}
}), BorderLayout.SOUTH);
return panel;
}
public void addElements() {
List<String> toAdd = new ArrayList<>(2);
toAdd.add("E");
toAdd.add("F");
this.values.addAll(toAdd);
}
private Component createComboBox() {
JComboBox<String> box = new JComboBox<>();
box.setEditable(true);
AutoCompleteSupport.install(box, this.values);
return box;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
ComboBoxTest testApp = new ComboBoxTest();
JFrame frame = new JFrame("ComboBox Test");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(testApp.createControl());
frame.setSize(600, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
}

nullpointer exception on table.getSelectedRow()

I have a class A and a class B.
In class A there is a constructor:
public A() {
getSelectedRow();
}
This constructor calls:
public int getSelectedRow() {
System.out.println("The row is : " + table.getSelectedRow());
return table.getSelectedRow();
}
Up to here everything works fine!
The class B then calls the method getSelectedRow() like that:
A results = new A();
System.out.println("YEAH! IT'S: " + results.getSelectedRow());
I just want to find out the selected table row from class A. The problem is that I am getting a null pointer exception and i dont know why. if I dont call the method everything works fine.
CLASS A:
public class AllResultsFromDB extends JFrame {
#SuppressWarnings("compatibility:9056676689615464658")
private static final long serialVersionUID = 188850508334531506L;
GUI ins = new GUI();
JTable table;
public AllResultsFromDB(GUI x) {
final Vector columnNames = new Vector();
final Vector data = new Vector();
this.ins = x;
try {
/** Initializing GUI class
* in order to call
* getSelectedTable() method. **/
Login sgui = new Login();
String dburl = "jdbc:oracle:thin:#localhost:1521:ORCL";
Connection connection = DriverManager.getConnection(dburl, sgui.getUsername(), sgui.getPassword());
// Fetch data from table specified by user
String query = "SELECT * FROM " + ins.getSelectedTable() + " ORDER BY id";
System.out.println(query);
Statement stmt = connection.createStatement();
ResultSet rset = stmt.executeQuery(query);
ResultSetMetaData metad = rset.getMetaData();
int columns = metad.getColumnCount();
// This loop gets the names of the columns
for (int i = 1; i <= columns; i++) {
columnNames.addElement(metad.getColumnName(i));
}
// This loop gets the data inside the rows
while (rset.next()) {
final Vector row = new Vector(columns);
for (int i = 1; i <= columns; i++) {
row.addElement(rset.getObject(i));
}
data.addElement(row);
}
rset.close();
stmt.close();
connection.close();
// Create table with results
table = new JTable(data, columnNames) {
public boolean isCellEditable(int row, int col) {
return false;
}
public Class getColumnClass(int column) {
for (int row = 0; row < getRowCount(); row++) {
Object obj = getValueAt(row, column);
if (obj != null) {
return obj.getClass();
}
}
return Object.class;
}
};
JScrollPane scroll = new JScrollPane(table);
getContentPane().add(scroll);
JPanel panel = new JPanel();
getContentPane().add(panel, BorderLayout.SOUTH);
table.addMouseListener(new MouseListener() {
public void mousePressed(MouseEvent e) {
//System.out.println(table.getSelectedRow());
}
public void mouseReleased(MouseEvent e) {
//System.out.println(table.getSelectedRow());
}
public void mouseEntered(MouseEvent e) {
//System.out.println(table.getSelectedRow());
}
public void mouseExited(MouseEvent e) {
//System.out.println(table.getSelectedRow());
}
public void mouseClicked(MouseEvent e) {
getSelectedRow();
if (e.getClickCount() == 2) {
//System.out.println(table.getSelectedRow());
Profile profile = new Profile();
try {
profile.getData();
//wait(500000);
profile.getImage();
} catch (Exception f) {
}
profile.setVisible(true);
}
}
});
} catch (SQLException e) {
}
}
public AllResultsFromDB(int x) {
x = getSelectedRow();
System.out.println(table.getSelectedRow());
}
public int getSelectedRow() {
System.out.println("The row is : " + table.getSelectedRow());
return table.getSelectedRow();
}
}
CLASS B:
public class Profile extends JFrame {
AllResultsFromDB results = new AllResultsFromDB();
public Profile(AllResultsFromDB x) {
this.results=x;
try {
getData();
getImage();
} catch (Exception e) {
e.printStackTrace();
}
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
public void getImage() throws Exception {
JLabel label;
Image img;
ImageIcon pic;
JPanel panel;
img = new ImageIcon("java.jpg").getImage();
pic = new ImageIcon(img);
label = new JLabel("", pic, JLabel.CENTER);
panel = new JPanel(new BorderLayout());
panel.setBounds(new Rectangle(0, 0, 340, 310));
panel.add(label, null);
panel.add(label, BorderLayout.CENTER);
this.getContentPane().setLayout(null);
this.setSize(new Dimension(1148, 336));
this.getContentPane().add(panel, null);
}
public void getData() throws Exception {
String url = "jdbc:oracle:thin:#localhost:1521:ORCL";
String username = "c##lambros";
String password = "16111111";
Connection conn = null;
try {
System.out.println("YEAH! IT'S: " + results.getSelectedRow());
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, username, password);
String sql = "SELECT foto FROM criminals WHERE id = 5";
PreparedStatement stmt = conn.prepareStatement(sql);
ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) {
//String name = resultSet.getString(1);
//System.out.println("Name = " + name);
File image = new File("java.jpg");
FileOutputStream fos = new FileOutputStream(image);
byte[] buffer = new byte[256];
//
// Get the binary stream of our BLOB data
//
InputStream is = resultSet.getBinaryStream(1);
while (is.read(buffer) > 0) {
fos.write(buffer);
}
fos.close();
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (conn != null && !conn.isClosed()) {
conn.close();
}
}
}
private void jbInit() throws Exception {
this.setSize(new Dimension(816, 380));
JLabel label;
Image img;
ImageIcon pic;
JPanel panel;
img = new ImageIcon("java.jpg").getImage();
pic = new ImageIcon(img);
label = new JLabel("", pic, JLabel.CENTER);
panel = new JPanel(new BorderLayout());
panel.setBounds(new Rectangle(0, 0, 340, 310));
panel.add(label, null);
panel.add(label, BorderLayout.CENTER);
this.getContentPane().setLayout(null);
this.setSize(new Dimension(1148, 336));
this.getContentPane().add(panel, null);
}
}
In the classB since you are creating a new instance
A results = new A();
The value present in the table.getSelectedRow() also gets created newly and will point to null.
So make sure that you do somthing
A results = new A(selectedRow);
and in the constructor of the A,pass the argument to the function
getSelectedRow(selectedRow);
Please note : Make sure that the value of the "table.selectedRow" is maintained
If table is your instance variable in Class A then it might not be initialized when you are trying to access it in constructor of A.
And calling getSelectedRow from the constructor is not making any sense too.
Try to initialize the table variable in constructor instead of calling that method, it should work after it.
This is because the table object is not being initialized.
Try to initialize the table object in constructor....it is a good practice

Categories