-1

Is there a way to typecast String type to JLayeredPane? Following is the code I am using:

private static void build_tables() {  
    String sql="SELECT * FROM pos_tables WHERE pos_company_id='"
        +global_variables.company_id
        +"' AND shop_type='"
        +global_variables.shop_type
        +"'";  
    if(mysql_query.count_mysqls(variables.con.conn, sql)>0){  
        try {  
            ResultSet rs = mysql_query.execute_mysql(variables.con.conn, sql);  
            while (rs.next()) {  
                JLayeredPane JL = (JLayeredPane)rs.getObject("parent_floor");  
                tablesetup.addButton(rs.getString("table_name"),
                    Integer.parseInt(rs.getString("x")),
                    Integer.parseInt(rs.getString("y")), JL);    
            }  
        } catch (SQLException ex) {   
            Logger.getLogger(builder.class.getName()).log(Level.SEVERE, null, ex);  
        }  
    }  
}  

I am getting the following error:

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException:
java.lang.String cannot be cast to javax.swing.JLayeredPane
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Deepak
  • 6,684
  • 18
  • 69
  • 121

1 Answers1

1
JLayeredPane JL = (JLayeredPane)rs.getObject("parent_floor");

A database doesn't contain JLayeredPane objects. It contains a string.

What are you trying to do? Why are you using a JLayeredPane?

Just use a JPanel. Then you can create a JLabel using the string returned from the database query and then you add the label to the panel.

Something like:

String text = rs.getObject("parent_floor").toString();
JLabel label = new JLabel( text );
panel.add(label);
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
camickr
  • 321,443
  • 19
  • 166
  • 288
  • i am using tabbed pane and inside each tab i dynamically add buttons and labels(inside another layeredpane) Can this be done by just using JPanel ? can i add another Jpanel inside Jpanel ? – Deepak Mar 19 '11 at 02:55
  • you can nest JPanels arbitrarily deep – MeBigFatGuy Mar 19 '11 at 05:22