I earlier had Oracle Java 7 installed on my Linux box. I upgraded to Oracle Java 8 as follows (below commands to be typed in a terminal window):$ sudo apt-get purge oracle-java7-installer <enter>$ sudo apt-get install oracle-java8-installer <enter> However, when Oracle Java 8 was downloaded and installed, I saw a message like this: update-binfmts: warning: … Continue reading How to resolve update-binfmts: warning: current package is oracle-java8, but binary format already installed by openjdk-7
Tag: java
GridLayout struggle when it has excess rows and how to overcome
In my Java code, I am using GridLayout (line shown in red) in code below: frame = new JFrame("Contacts Details"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainPanel = new JPanel(); buttonPanel = new JPanel(); mainPanel.setLayout(new GridLayout(9, 3)); buttonPanel.setLayout(new GridLayout(1, 3)); The result was this: Name [ ] (Text Box for name) City [ ] (Text Box for City) Cell [ … Continue reading GridLayout struggle when it has excess rows and how to overcome
Where to place a text file for use with a Java project in Eclipse
I placed a text file myapp.txt in the folder ~/workspace/PayrollApp/src/org/username/payrollapp. However, it was not opening in the Java program. To make it work correctly, I had to do use the following path in the Java program when opening the file: src/org/username/payrollapp/pay.txt Code as follows: try { FileReader fr = new FileReader("src/org/username/payrollapp/pay.txt"); BufferedReader br = new … Continue reading Where to place a text file for use with a Java project in Eclipse
Where to place SQLite 3 database for use in a Java Project in Eclipse
My Eclipse Java project path is as follows: ~/workspace/PayrollApp/src/org/username/payrollapp/payroll.db I had placed the SQLite database file payroll.db in the above path, and found it was not getting used when I ran the Java program. Upon inspecting the contents of ~/workspace/PayrollApp, I found that payroll.db was there with 0 bytes. That implied that the file needs … Continue reading Where to place SQLite 3 database for use in a Java Project in Eclipse
Window Builder Pro hangs in Eclipse Luna on Ubuntu 14.04 LTS
If you use Eclipse IDE for Java development, you will find that there is a great GUI builder from Google, and it worked very well on previous releases of Ubuntu. Unfortunately, Eclipse just freezes when you use Windows Builder on 64 bit Ubuntu 14.04 LTS. Several posts on the Internet suggest installing Oracle Java 7 … Continue reading Window Builder Pro hangs in Eclipse Luna on Ubuntu 14.04 LTS
How to make a form refer to the parent frame using a JDialog
Below code segment shows how to use a JDialog to refer to a parent frame. MyApp.java public class MyApp { JDialog dialog; JFrame parentFrame; public static void main(String[] args) { MyApp app = new MyApp(); app.gui(); } public void gui() { //The parentFrame parentFrame = new JFrame(); parentFrame = setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //The dialog dialog = new … Continue reading How to make a form refer to the parent frame using a JDialog
How to remove all rows from a Java JTable created using Custom TableModel
To remove all rows from a Java JTable created using Custom TableModel, try the following: MyModel myTableModel = (MyModel) myTable.getModel(); for (int i = myTableModel.getRowCount()-1; i >= 0; i--) myTableModel.deleteRow(i); Define the deleteRow(int row) method in the MyModel class.
Display a popup message in Java Swing
At times, we need to show quick messages in a small window on screen to users in Java. Here is a quick way to do this. import javax.swing.JOptionPane JOptionPane.showMessageDialog(null, "This is my Message Dialog");
Read data from a JTable created from AbstractTableModel
If you have a JTable in Java created with an AbstractTableModel, you can read the data from it, using following: int rowCount = testTable.getRowCount(); for (int i = 0; i < rowCount; i++) { String mColumn1 = (String) testTable.getModel().getValueAt(i, 0); String mColumn2 = (String) testTable.getModel().getValueAt(i, 1); } Alternatively, you could also try where the JTable … Continue reading Read data from a JTable created from AbstractTableModel
Java program bug due to multiple declaration of variable in code and the fix
I created a small Java class to accept a date. However, when I tried to use it, I got a NullPointerException error. This post is just to illustrate how it was fixed. 1 public class DateForm { 2 JFormattedTextField txtMyDate; //This is a variable at class level 3 4 dateForm () { 5 JTextFormattedField … Continue reading Java program bug due to multiple declaration of variable in code and the fix