Michael Cleary

Ranch Hand
+ Follow
since Jul 29, 2003
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
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Michael Cleary

Oops - I should have looked at the post after I entered it. The second output, when pasted into this window (i.e. where you type your post), was lined up perfectly.

In any case, I'll try changing the font as suggested and see how it looks.

Thanks
15 years ago
I'm trying to format some text which is being placed in a JTextArea in a JScrollpane. I am looping though an ArrayList and pulling out the values I need. I have set the String format as follows:

temp = String.format("%1$-20s %2$4s %3$6s%n", name, qty, price);

When the output appears in the JTextArea it looks kind of like the following:

However, if I copy the output from the JTextArea and paste it here, it looks great - exactly like I want it to.

Can anyone please tell me why it does not appear correctly in the JTextArea of my GUI?

Thanks,
Mike

[ EJFH: Added "CODE" tags to preserve formatting. ]
[ October 11, 2006: Message edited by: Ernest Friedman-Hill ]
15 years ago
Had to add this to my previous post. When I said I couldn't "see" the setter method, I meant that in the IDE I'm using (JCreator Pro), it presents a drop-down list of available methods when you invoke an instance of a class. I do not see my "setter" in this list, but I do see the "getter". However, if I go ahead and add the line:
gui.setTotalField(total);
the controller class compiles just fine. Perhaps a weird bug in the IDE?
15 years ago
I am concerned w/ two classes here. One is a class which creates a GUI with various buttons, a JTextField and a JTextArea. The other class is a "controller" class whose constructor creates an instance of the GUI class (named "gui" of all things...). The controller class is supposed to handle events generated when one of the buttons on the GUI is clicked.

The GUI class constructor sets up all the gui components. Also in the GUI class I have two methods: one is a "getter" which returns a String array which is a list of button names. The other is a "setter" which sets the text in the JTextField.

Within the event handling method of the controller class I can invoke the "getter" method via "gui.getButtonNameList". However, if I try to invoke the "setter" method (named setTotalField), I cannot even see this method from the controller class. Both methods are public of course; the getter returns a String[], and the setter is void.

I don't understand why I cannot see the "setter" method from the controller class....??

Any assistance would be greatly appreciated!

Thanks,
Mike
15 years ago
I'll take a look - thanks! And yeah, I use regex in PERL on a daily basis! I was hoping Java had something similar - I've just never used it before.

Thanks again,
15 years ago
The patterns will vary a bit. One will be a persons name in the form of either "lastname" or "lastname MI". Another might be a number in the form of "3.00" (no quotes on any of them of course). I'm trying to help my son out a bit w/ an assignment (and no, I'm not doing it for him). I got my SCJP a couple of years ago, got to work on one Java project at work, and since then I've been stuck in PERL. So unfortunately, I'm a little rusty w/ Java.

Thanks,
15 years ago
Can anyone point me to any references/examples of parsing text in java? I basically need to search lines in a text file and look for certain patterns, etc. Are there some regular expression classes / methods that are useful for this sort of thing?

Thanks,
15 years ago
I made a quick browse of the Bunkhouse, and so far I like the look of the "Step by Step" book on Eclipse. I looks like a good place to start anyway.

Thanks,
16 years ago
Yes, that makes sense. But the example is one of the examples that comes w/ Eclipse. When I first opened the example, it said it needed to be installed, so I let it install it. I obviously don't know enough about Eclipse...

Thanks,
16 years ago
Because I never get to use Java at work, I've decided to work on my own project at home. A portion of it will involve being able to create/modify/save multipage documents. The documents will all follow a basic table-like format (more like a form I guess), but which can be modified in certain respects (i.e. # of rows). The number of pages will vary as well.

I have searched for examples of multipage editors (in Java) and have not come up with much. I found an example in Eclipse, but not being an Eclipse user I haven't been able to get it to run properly. Every time I try to "Run" it according to the instructions, it just opens another instance of Eclipse....
I'll probably try copying the code into another editor and try it from there.

If anyone knows of other similar examples they could point me to, or even places to look, I would very much appreciate it!

Thanks,
16 years ago
Well, it sounds to me like I need to get off the fence and try Eclipse again! The IDE I have used the most is JCreator Pro, which of course is not free. But is is a very nice IDE and I've gotten pretty used to it. At work I had to use NetBeans for a project last fall, and I didn't really care for it that much. But again, it may have been simply because I was so used to something else.

Thanks,
I have always been somewhat put off by Eclipse because it seemed that there was such a steep learning curve just to use the thing. To be fair, I have not tried Eclipse in a long time, so this may no longer be a valid concern. Is your book primarily concerned w/ the new features in 3.0, and therefore assume a prior working knowledge of Eclipse? Or would new users be able to use it as a guide to start working with Eclipse?

Thanks,
Mike
Thanks - worked like a charm...
16 years ago
I have the same problem - probably because I am also populating the text area using the append method. Here is my code:

private void getData(String file){
String log = file;
String line = "";

try{
reader = new FileReader("c:\\STB_Code\\" + log);
in = new BufferedReader(reader);
while( (line = in.readLine()) != null) {
//write the line to the display area
logDisplay.append(line + "\n");
}//while
}//try
//process exceptions from opening the file and reading lines
catch(FileNotFoundException filenotfoundException) {
JOptionPane.showMessageDialog(this, "File Not Found",
"Error", JOptionPane.ERROR_MESSAGE);
}//catch
catch(IOException ioEx) {
JOptionPane.showMessageDialog(this, "Error Reading Line",
"Error", JOptionPane.ERROR_MESSAGE);
ioEx.getMessage();
}

//Close the file
try {
reader.close();
in.close();
}
catch(IOException ioEx) {
JOptionPane.showMessageDialog(this, "Error Closing File",
"Error", JOptionPane.ERROR_MESSAGE);
ioEx.getMessage();
}

}//end getData


Did you solve this problem? If so could you please share?

Thanks,

Mike
16 years ago
I have a small app in which users can open a number of files in JInternalFrames (w/in the main JFrame). I know how to "cascade" the open windows, but I would also like the user to be able to arrange them horizontally and vertically (i.e. for comparing 2 files side by side). I have been searching the web for an example, but so far have come up empty. Can anyone point me to just such an example?

Thanks,
Mike
16 years ago