Derek Boring

Ranch Hand
+ Follow
since Aug 15, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Derek Boring

I was not aware that method existed! I will rewrite my code to utilize System.currentTimeMillis, thank you!
Hi everyone!

So in my latest application, I have my main JFrame window and a background worker thread. When you click the 'Start' button on the main window, it starts the background worker thread and also sets a java.util.Timer using:



The timer's job is to increment a milliseconds variable to keep track of exactly how long the background thread takes to execute and also provide a time stamp relative to the start time for when the background thread prints to the log. The problem I am running into is the timer seems to not be calling the TimerTask (IncrementTime extends TimerTask) object's run method. If I set the delay parameter to 0, the run() method gets called once, but never again.

I create the timer object as a public field in my main window's (extending JFrame) class code using:


Here's all the possibly relevant code from the 'Start' button click event:

sendStopSignal(boolean stop) is a method I wrote into my AnalyzerProcess() class to gracefully and cleanly stop its current activity and then end the thread's execution.

The last thing the worker thread does before it finishes it's execution is call this method on the JFrame:


Here's my TimerTask extension class:

The System.out.println() never gets called.

This may be unnecessary, but just for completeness, here is my IncrementTime() method:


If you need any other info please let me know. Thank you so much in advance for your help! You guys here are all super awesome!
There is an exclamation point in front of database.exists(), thus if it returns false, the code following the if statement would be executed.
10 years ago
Hello everyone,

I've been having this issue for a week and no amount of Google searches has helped me figure it out. My interface is written in Swing, but I use the AWT FileDialog to have the user choose a file to save their data to. (I chose this method because it uses the native file chooser since the JFileChooser is absolutely horrid and completely unusable on Mac) Once the user chooses the file, I get the File from the FileDialog object and then check if it exists. If it does not, I use the File class's createNewFile() method. However, the method returns false and does not create a new file. canRead() and canWrite() both return true. I have tried choosing several different locations to save to, (even the root directory) but I get exactly the same result no matter where I choose. Is there something I am missing?
Here is my code:



The System.out.println() displays this result:

file created: false Read/Write Permissions: true/true

and, of course, no file is actually created.
Just in case it makes a difference, here is my development environment info:

Intel based MacBook Pro, OS X 10.9.2
Eclipse, Version: Indigo Service Release 2, Build id: 20120216-1857
Java, Version 7, Build 51 (build 1.7.0_51-b13)

Can anyone please help me figure out why it's not creating a file?

Let me know if you need any other information. Thank you in advance, you guys here are all freaking awesome!
10 years ago
Thank you so much! Your suggestion works perfectly!
10 years ago
Hi everyone!

First off, you guys are awesome! I love this forum!

Now my issue is I have a JTable. The first column will contain Date objects all the way to the bottom. I want the JTable to display only the month and year. I created a custom cell renderer, but it appears the cell renderer method "getTableCellRendererComponent" is never called. (I tested it using System.out.println();) Here is my code for setting the cell renderer and the contents of the first column:



The Date objects are set into the cells of column 0 correctly. The table shows the result of the "toString()" method for each cell in that column.
If you need to see the code for the cell renderer I can post it. I am certain the problem is the cell renderer is not getting called though. Can you help please?
10 years ago
Oh my gosh!!!


How on earth did I miss that?!?


Thank you so much!!!


You are the best! I can't believe I didn't pick up on that. Thank you again!
10 years ago
Hello Friends,

I'm having an issue that several hours of google searching and tweaking has been unable to resolve. I'm reading an XML file using Java DOM. That part is working correctly. Each element within the file contains a date attribute that is in the format of "MM/DD/yyyy" e.g. "07/23/2013" I am trying to use a SimpleDateFormat object to parse the string into a Calendar object. It correctly reads the day and year into the Calendar object, but always returns January (1) as the month. Here is the code I am using:



The SimpleDateFormat object's parse method returns a Date object, so here is my method to convert the Date object to a Calendar object:



Is there something I am missing or doing incorrectly?

EDIT:
I added the following line to the dateToCalendar method just to see what the output would be:



It prints out 0 when the month in the input string is "07". So it seems to me that the problem is with the SimpleDateFormat object and not the Date or Calendar objects, and not with the dateToCalendar method. Any ideas?
10 years ago
Hi everyone, it's been awhile, but I'm glad to be back.
I'm making a program to layout photos in a collage, grid style. I've created a custom component that extends JPanel, called PhotoPanel. Each PhotoPanel paints it's photo on the JPanel with a transparent background. I layout the PhotoPanels in a JPanel (called the PagePanel) using GridBagLayout. Each PhotoPanel has an instance of GridBagConstraints. When properties are changed for either the page or the selected PhotoPanel, the selected PhotoPanel's GridBagConstraints is updated, and the page layout is redone: e.g. all components are removed from the PagePanel and then readded using their own, updated GridBagConstraints object. The idea is that each photo can be set up to occupy multiple cells in the grid, using the GridBagConstraints 'gridwidth' and 'gridheight' properties. My method to add all of the PhotoPanels to the PagePanel keeps track of 'row', 'column', 'maxRows', and 'maxColumns' variables to control where the PhotoPanels are added. They are simply added in sequential order like so:

set the PhotoPanel's constraints, including 'row' and 'column'
page.add(PhotoPanel, PhotoPanel.myConstraints);
column++
if(column >= maxColumns){
column = 0;
row++;
}

What I want is to check the GridBagLayout to see if there is already a component occupying the cell at position "row,column" so that I can skip that cell. My current approach is that I create a boolean array of size [maxRows][maxColumns] and then set the "cells" where I add components to true. For components that occupy multiple cells on the PagePanel, multiple "cells" in the array are set to true in the proper positions. It works the way I want it to right now, but I feel like it would be more reliable to be able to "ask" the GridBagLayout if a certain cell is already occupied. Is there a way to do this? or should I just stick with my boolean array?
11 years ago
Hi Everyone,

If this is in the wrong place, please forgive me. I am writing a fairly simple program to manage leads for my business. This is not a full blown CRM type of project, nor am I ever intending it to be. It's purpose is simply to keep track of the leads' contact information and keep a history of what was accomplished each time the lead was called. (leads being prospects for sales in this instance) I currently have it set up to use a separate file for each individual lead that contains all of the lead's information and history. I'm using a JTree to show the groups and subgroups (directories) and the leads (files). This works decently now, but loads very slowly. I'm considering the options of loading all the leads lazily, or switching to a database. I want to switch over to a database for better performance and because I know it's just the better way to do it. I'm having a terribly tough time understanding how to use JDBC. I took two years of Java programming courses and two semesters of Oracle database, but that was several years ago and we never mixed the two. Can anyone here point me to a very simple database I could use? The database will not be accessed my multiple users, and not even multiple instances of the program. I don't want to have to install anything (such as a DB Server) on my work computer, I just want to be able to email the JAR to my work computer and use it. If nothing like this is available, can anyone point me to a "JDBC Tutorial for Dummies" sort of thing? I really appreciate everyone here, you guys are awesome.

-Derek
Do you mean you want the mouse in the screenshot?
If you don't, then that is how the mouse is kept out of the shot, Java tells the OS not to draw the cursor before it starts the capture, then when it is finished capturing, it tells the OS that it can draw the cursor again. I'm not sure how to get the cursor in the screen shot other than to get an image of the cursor and the coordinates of it and draw it on the screenshot yourself.
15 years ago
I making a simple formatted text editor, such as WordPad that comes with Windows. Nothing fancy like MS Word or OpenOffice Write, just simple formatting that can be done all with HTML. It's kind of like a journal, the reason I'm using HTML instead of RTF is because I want to be able to display the text in a JLabel with the formatting later on. What doesn't work is that the JEditorPane shows the HTML tags rather than formatting the text between them. I've tried both typing in the tags myself and using something similar to txtDoc.setText("<B>This is bold.</B>"); or txtDoc.setText("<HTML><B>This is bold.</B></HTML>"); and it still just shows the tags. (even the <HTML></HTML> tags)
15 years ago
I have researched development for the iPhone and iPod Touch as I too have wanted to develop apps for them. What I have found is that there is no legal way to run Java on either device yet. These devices run and only run programs created using Apple's objective C SDK and libraries.

However, I have found two roundabout ways to get Java to "run" on these devices:
The first is to crack the OS to allow a Java ME Virtual Machine to run. However, when you download an OS update, there is a high risk that it could brick you device.
The second way is not available yet, but supposedly will be in early 2009. Sun is working on a program to convert Java ME code into Objective C code that will run on these devices. Supposedly the converted programs will require no modification before being compiled. It is said that Sun is working with Apple on this project, but Apple doesn't really endorse it.

I read this on a website, but I don't remember what site. I just did a google search for "java on iphone"

Hope this helps!
15 years ago
I did something similar once. I don't remember the exact implementaion, but I do remeber I extended the component, and then I modified the paint() method to draw the background (e.g. your icon) and then it would call super.paint() which would draw the rest of the component. I believe I had to do "super.setOpaque(false)" but I don't remember for sure.

Hope this helps!
15 years ago
I've been trying for some time to get a JEditorPane to properly display text formatted using HTML. No matter what I try, I just can't seem to get it to work. I can't find any tutorials that help either. If someone could please provide me a short example and/or a good explanation of how to do this, it would be greatly, greatly appreciated.

p.s. I want the user to be able to edit the text and apply formatting.

Thank you in advance!
15 years ago