Cast java List class

Question: I have an Android mobile phone application and a quick Java question. I have a class method that returns a List Object. In the list I have “otherclass” items. I would like to cast all the “Object” items in that list to “otherclass” that I’d end up with List ‘otherclass’. I was told it could not be done. Is it true? My code:
public class otherclass {    
    public List<object> getDataList(){}    // It returns a List<object>
}

public class TestClass extends otherclass{
    // I can't cast its list here to List<otherclass>. Compile fires an error at:
    List</otherclass><otherclass> o = (List</otherclass><otherclass>)getDataList();
}
</otherclass></object></object>
Continue reading Cast java List class

Populate java combo box with mySQL table value

Question: I have a Java NetBeans 6.9.1 project. In the desktop application when I am binding a combo box to mySQL database table and run the form, I get a combo box that is filled with root information of database row pks. This data presentation is useful for system administrators but not for my customers. I cannot select and see a value from my data entity class! I checked it several times. Data query and list work fine. The Name and Description fields are present but not shown. Can a combo box be used in a more elegant way? Continue reading Populate java combo box with mySQL table value

Binding JTable with mySQL data in Java NetBeans

Problem: In a Java swing desktop application I try to bind a remote mySQL database table to a JTable. NetBeans takes care of all the GUI and persistence part. I built a JFrame form that has a JTable bound to a mySQL table. The query is dynamic and depends on the user’s selection, that actually becomes the WHERE clause. I spent a day trying to include a WHERE clause in the query. After a heavy internet search I figured it out, but when I set the frame to visible the new data is not shown. The JTable repaint() method does exactly nothing. I tried messing up with the fire action listeners, but I couldn’t get that to work either. The JTable has no data refresh method. Can anyone of you tell me the way to have my JTable displayed after an sql query is executed in runtime? I am attaching my code. Continue reading Binding JTable with mySQL data in Java NetBeans

Customize UINavigationBar buttons with image

Question: While I am developing an application for iOS 3.2 (iPad) and iOS 4 (iPhone) targets, I have to customize the navigation bar. We know that the default behavior of the navigation controller is to provide a back button with the title of the previous view controller in the queue. In my project I have to change the default look of the back button with a custom view and I have to add a home button on the right, that takes the user to the first page’s view controller by calling popViewController. The right button works and looks fine but I cannot change the back button’s image. What’s wrong? My code:
    // Hide original back button
     self.navigationItem.hidesBackButton = YES;
    // Add Left Button to act as Back Button  
    UIBarButtonItem *backButton = [[[UIBarButtonItem alloc]  
                            initWithImage:[UIImage imageNamed:@"back-button.png"]  
                            style:UIBarButtonItemStylePlain  
                            target:self  
                            action:@selector(backTo)] autorelease];  
    self.navigationItem.leftBarButtonItem = backButton;
Continue reading Customize UINavigationBar buttons with image

Blog for us