Forums Register Login

Having issues in displaying content of an arraylist and displaying the content in real time

+Pie Number of slices to send: Send
I'm quite new to Java and I know that the best way to learn is to have personal projects to work on. I've been working on a clipboard manager that keep a history of what the user copies.
I managed to do what I wanted when the user copies some text, the data is stored in a arraylist. My problem comes from the GUI ,I've tried several things but I can't manage to display the data of the ArrayList.
My problem is that I don'T know exactly where to create the GUI, in the main class or in the Thread that does all the doing? secondly since the data keeps adding whenever the user copies, the list has to be updated in real time to display the content of the list is there any way to achieve that ? Any tips would be appreciated
+Pie Number of slices to send: Send
Welcome to the Ranch

Rachid Insa wrote:. . . the best way to learn is to have personal projects to work on.

Yes and no. It is good to have a project you want to complete; that provides lots of motivation, but without guidance you can go seriously wrong. Even code which appears to work can be written incorrectly. Show us the code and we can help guide you.

I've been working on a clipboard manager that keep a history of what the user copies.

Please explain more; the clipbouard is an operating system feature and Jaa® as a language is not very good at getting at low‑level operating system stuff.

I managed to do what I wanted when the user copies some text, the data is stored in a arraylist. . . . I can't manage to display the data of the ArrayList.

Can you display the List at the terminal/command line? You shou‍ld be able to run any applications from the command line without a GUI and then make the List available to the GUI later.


My problem is that I don'T know exactly where to create the GUI, in the main class or in the Thread that does all the doing?

Don't know. I actually think both those locations may be wrong, however. But GUIs are for later on.

. . . the list has to be updated in real time to display the content of the list is there any way to achieve that ? . . .

That sounds like a job for a worker thread, which you can use via an instance of the Swing worker class, but get the List sorted out first.
+Pie Number of slices to send: Send
 

Campbell Ritchie wrote:Welcome to the Ranch


Thanks , so my code goes as follows:

So basically whenever there is an update in the content of the clipboard, the content is stored in the ArrayList. At first I make sure to clear the clipboard so that there is no unpleasant surprise. That is the way I found to keep a history of what the user copies. I wanted it to only store 10 piece of data or string in this case and should act as a queue (so FIFO). I can display the ArrayList at the terminal/command line that is the reason why I wanted to go a step further by making the List available to the GUI. And my main class is quite simple:

+Pie Number of slices to send: Send
Line 23 looks totally disastrous, I am afraid. I think that needs to go. Or maybe you intended it to be the end of a do loop?
I had forgotten that a Toolkit object allows you access to the clipboard. I am not familiar with the code which declares those exceptions, least of all line 32. Please consider making your listener class implement Runnable rather that extending Thread. You will have to use a different thread for Swing purposes, so it is probably right that you run the listener in its own thread. And it is right that you haven't yet created a GUI.
Consider using multiple catch with the | operator.
If you want a queue with a limited size, why are you using a List? Go through the Java™ Tutorials and see whether there is a Queue implementation with a limited size. (It might be that the two kinds of blocking queue will do what you want.)
+Pie Number of slices to send: Send
Well line 23 is to constantly check the content of the clipboard in case there is an update, if I remove it, it won't be able to detect when there is a change or maybe I should write it in another way that would be cleaner.
Concerning the rest I will follow what you advise me to do and see how it goes. I removed the GUI elements since I had it all wrong .
+Pie Number of slices to send: Send
Line 23 as written is an infinite loop. Maybe there shou‍ld be a do somewhere which you have missed out. Or maybe I am making some other mistake.
We don't have time to be charming! Quick, read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 374 times.
Similar Threads
Cut/copying and pasting custom object types
Is there any way of getting an image from the system clipboard?
Need help with clipboard.
Clipboard "event"
Forwarding data changes in MVC
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 09:07:38.