How to UnFocus a JTextField

Questions: When my application loads, which is made using netbeans, the first JTextField is automatically focused, and in this JTextField, I have written “Enter your Username”, it will go away when the user clicks on this field, but when the application is loaded, this field is focused, means I can’t see “Enter your Username”, how… Read More »

Java XML Parser for huge files

Questions: I need a xml parser to parse a file that is approximately 1.8 gb. So the parser should not load all the file to memory. Any suggestions? Answers: Aside the recommended SAX parsing, you could use the StAX API (kind of a SAX evolution), included in the JDK (package ). StAX Project Home:… Read More »

Why are my items not showing up in JFrame?

Questions: I’m fairly new to JFrame and I want to know why my items are not showing up on the window. I know i dont have a ActionHandler but I just want my textfield’s to show up on my window. Here’s my code: import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; public class… Read More »

Get resource from jar

Questions: I have jar with files: myJar/res/endingRule.txt myJar/wordcalculator/merger/Marge.class In I have code: private static final String ENDINGS_FILE_NAME = “res/endingRule.txt”; …. InputStream inputStream = getClass().getClassLoader().getResourceAsStream(ENDINGS_FILE_NAME); ….. But after this inputStream is null. How to work with resources? Why null? Answers: To retrieve the file inside the jar, use: private static final String ENDINGS_FILE_NAME = “/res/endingRule.txt”;… Read More »

More efficient way for pausing loop wanted

Questions: Is it possible to rewrite this code for better working with processor? I have a class, which does some tasks with fixed periodicy in a separate thread. Sometimes this process can be paused and resumed. Currently I am using a flag for pausing, it works fine, but loop in this way still loads processor… Read More »

javafx automatic resizing and button padding

Questions: I’m trying to make an on screen keyboard with Javafx for the layout. I’m using the Scene Builder to make the FXML file. <?xml version=”1.0″ encoding=”UTF-8″?> <?import java.lang.*?> <?import java.util.*?> <?import javafx.geometry.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.paint.*?> <?import javafx.scene.text.*?> <AnchorPane id=”AnchorPane” maxHeight=”-Infinity” maxWidth=”-Infinity” minHeight=”-Infinity” minWidth=”-Infinity” prefHeight=”186.0″ prefWidth=”600.0″ xmlns:fx=”″ xmlns=”″> <children> <VBox layoutX=”0.0″ layoutY=”0.0″… Read More »

Java KeyListener stutters

Questions: I’m making a very simple pong game in java and I’m doing this using KeyListener. I want it so when the user presses the right or left keys on the keypad, the pong block goes in that direction. This is a simple enough task, but what I’m finding out is that when the user… Read More »

java.lang.ClassNotFoundException: when starting Simple Struts2 Application

Questions: I am trying to run a simple Struts2 application but it always throw the following exception: java.lang.ClassNotFoundException: I have followed the step by step tutorial in but I cannot make it work. I also managed to find other Struts2 tutorial which uses maven but all failed. It throws the same exception when… Read More »

Gradle always does println from any task

Questions: I have simple build.gradle (or any build.gradle with task that has println) println GradleVersion.current().prettyPrint() task task1{ println ‘task1 starting’ } Now when I run $ gradle build I always see tasks executing or print output task1 starting :compileJava UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :jar :assemble :compileTestJava UP-TO-DATE :processTestResources UP-TO-DATE :testClasses UP-TO-DATE :test UP-TO-DATE :check… Read More »

SimpleDateFormat producing wrong date time when parsing “YYYY-MM-dd HH:mm”

Questions: I am trying to parse string (YYYY-MM-dd HH:mm) to date, however getting wrong date than expected. CODE: Date newDate = null; String dateTime = “2013-03-18 08:30”; SimpleDateFormat df = new SimpleDateFormat(“YYYY-MM-dd HH:mm”, Locale.ENGLISH); df.setLenient(false); try { newDate = df.parse(dateTime); } catch (ParseException e) { throw new InvalidInputException(“Invalid date input.”); } Produces: Sun Dec 30… Read More »