Atrus Greyor

Ranch Hand
+ Follow
since Mar 07, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Atrus Greyor

How would I/is there any way to let the user select a file from my Application? For example, I'm making a book reading app, so I'd like to let the user be able to select an appropriate file. Is there any guaranteed way to give the user this ability?

Thank for the help.
14 years ago
Ah, okay. I wasn't aware that it created a new Graphics2D object, thank you very much.
14 years ago
With the following code, I'm unable to get an image to display the given character...



What exactly am I doing wrong?
14 years ago
I apparently wasn't sure of my question either. Thanks for helping to point me in the correct direction though.
14 years ago
What's hanging me up with that is I would like the column to display both ImageIcons and Strings. So I don't think that the "getColumnClass" is the right way to go. Unless it needs to be written in a way that I'm just not seeing.
14 years ago
How exactly did you use the DefaultTableModel? I did it like the below, and I still only saw the path to the image.

14 years ago
Okay, I see what my problem is, but, I'm not exactly sure how to fix it.

With the below, it imports correctly, however the images do not display correctly, showing their filename instead of the actual image:



I learned before that for the JTable to properly display ImageIcons, you need to add the getColumnClass method to the table. Which I did.



This is where the problem lies, and where you have to double click to see "Moo".
14 years ago
Here is my TableModel:



There isn't anything special. I don't modify the "setValueAt()" at all. However it does extend DefaultTableModel instead of AbstractTableModel
14 years ago
I'm using the basic JTable.

If my JTable is named data, and I call:

data.setValueAt("Moo", 1, 1);

The String is inserted, however, it's not visible unless I double click on the cell. How do I modify the cell so that it will appear without me having to double click?

Thanks,
Atrus.
14 years ago
Is any other information needed to help answer this question, I'm really stumped.
14 years ago

Matthew Cox wrote:You can't cast to it at Compile time if I am understanding your question correctly. When using Reflection, you are essentially giving up compile-time type checking and all the conveniences that come with it in order to gain the ability to "dynamically cast" as people seem to always describe it. Read up on Reflection and examine some coding examples. Reflection is tedious, run-time error prone (if not carefully coded), and if I remember correctly ... has a lot of overhead associated with it (not sure on this one). So be careful about how and when you decide to use it.

Someone in an earlier post mentioned a much simplier design ... it won't scale well but if you are only handling 4 or 5 classes and interfaces tops ... then creating a switch block of if block and using instanceof would be the best (meaning easiest) route. =D

GL



It's hard to do an if tree when the only information you have about the class is that it is a child of Z. It could be a class named A, B or something completely random.

However, I was able to solve it through reflection, thanks a lot Henry.
14 years ago
And then how would I go and cast that? I haven't ever used reflection, at least not knowingly.
14 years ago
I'm trying to implement D&D so that I am able to drag items from a JList. The JList contains either text or images, and I want the image to appear in the cell. My problems are:

  • When I try to drag a text element, and drop it, a white square appears. If I double click on the cell, I can see the text element.
  • When I try to drag an image element, I can't. It won't even let me. It comes from the same list as my text elements, so I don't understand why I can drag items in the list that only have text, but not ones that only have an image.


  • Here is my TransferHandler....

    14 years ago
    What if I know that the class is a subclass of Z, but I don't know the name of the class itself?
    14 years ago
    For example I have class A, B, C and D all of which extend Z

    Now I have ArrayList<Z> list = new ArrayList<Z>()

    I've put several objects of type A, B, C and D in the list, randomly, and I don't know anything about the order.

    How do I pull these items out with the correct type?
    14 years ago