Category Archives: Java

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

Cancel window closing operation in java app

Question: In my Java swing crossplatform project I have to ask the user if he/she really wants to quit from the desktop application before exit, so I have to handle the WindowClosing event. My problem is simple. I expected the DO_NOTHING_ON_CLOSE flag to prevent the form from closing. I didn’t thought the WindowClosing event will be fired even if the setDefaultCloseOperation was set to DO_NOTHING. When I even click on the NO button the window does close! Have you experienced it before and what have you done? Thank you in advance. I am attaching my code. Continue reading Cancel window closing operation in java app

Change data on PDF master page with iText

Question: I am using Adobe LiveCycle ES2 to design multipaged and taylor made PDF documents containing interactive forms. We build JAVA web server applications to manipulate these online PDF documents with iText 5.0 API library. By using LiveCycle I created a static XFA form with one master page and some watermark and text fields on the footer. I want to change these on the fly. I got a strange result. I added some text fields like TextWatermark, TextFieldDate and TextFieldName. The form I have created contains 10 pages so I expected Adobe Reader to present those fields on all the pages. The first page looks OK but my iText solution does not automatically update all other associated pages. What’s wrong? Continue reading Change data on PDF master page with iText