0

I am working to create a custom layout for an application, as I am not able to implement the functionality using existing layouts like CardLayout.

I need to store various Component instances in a collection. As, I see in CardLayout source code, they've used Vector to hold Card instances.

By going through many answers on StackOverflow, I have learned, we should use ArrayList over Vector. But, which one should we prefer in the case of GUI related applications like holding Component instances in a LayoutManager.

Akshat
  • 720
  • 9
  • 24
  • 6
    Why do you think it makes any difference whether you create a GUI application or not? CardLayout uses Vector because it has been written when List didn't exist. – JB Nizet Jan 24 '15 at 14:13
  • I thought that as all events in Swing are executed in EDT thread, so in a GUI application scenario, the collection does not need to be thread-safe to hold components. So, ArrayList would be better in that case!! – Akshat Jan 24 '15 at 14:18
  • @JBNizet As it is today, we should go with List? :P – Akshat Jan 24 '15 at 14:20
  • You said it yourself: *I have learned, we should use ArrayList over Vector* – JB Nizet Jan 24 '15 at 14:21
  • Ok. There is an another little problem, I am having trouble with. I need to get the Key from a HashMap whose Value is known. As I know, there is no method for that or it is not considered as a good practice! – Akshat Jan 24 '15 at 14:28
  • 2
    That has nothing to do with your question. But if that's what you need, you should probably have a Map instead of a Map. Or a BiMap. Don't forget that there might be several keys having the same value. – JB Nizet Jan 24 '15 at 14:31
  • See also [this](http://stackoverflow.com/q/5654926/230513) and [this](http://stackoverflow.com/q/24815413/230513). – trashgod Jan 24 '15 at 15:19
  • @trashgod Thanks for pointing out! I already seen your answer! And, for "implementing back/forward feature", what I need is full featured navigation with back/forward queue and breadcrumb support! And I am almost done with the layout! :D – Akshat Jan 24 '15 at 16:07
  • Note how @camickr's [answer](http://stackoverflow.com/a/5657106/230513) uses a `List` internally. – trashgod Jan 24 '15 at 16:19

0 Answers0