0

It's been 13 years since I last worked with Java and I'm lost. Someone please toss me a life saver.

I want to add the JPanel requesting the address to display on the JFrame by adding it from a JToolBar. Each component is in a separate class.

Question is, the button is on a toolbar and the panel I want to add is a separate class. Any ideas?

enter image description here

enter image description here

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Michael Mouer
  • 127
  • 1
  • 2
  • 8
  • Sounds like you just need a button click event that toggles the display of the JPanel? Make a method in the JPanel class that toggles the correct visibility of components and call it from the button click event. – sorifiend Oct 19 '20 at 22:05
  • Display a modal JDialog with your panel. When the dialog is closed you copy the data from the dialog to your JTable. – camickr Oct 19 '20 at 23:56
  • Further clarification, all my previous Java experience was backend.Would it be better to use a menu item instead of a toolbar. to add a JPanel to the original JPanel. – Michael Mouer Oct 20 '20 at 21:18
  • Tip: Add @sorifiend (or whoever, the `@` is important) to *notify* the person of a new comment. – Andrew Thompson Oct 21 '20 at 15:54
  • 2
    *"Would it be better to use a menu item instead of a toolbar(?)"* It should make no difference. *"to add a JPanel to the original JPanel"* Use a [`CardLayout`](http://download.oracle.com/javase/8/docs/api/java/awt/CardLayout.html) as shown in [this answer](http://stackoverflow.com/a/5786005/418556). – Andrew Thompson Oct 21 '20 at 15:56
  • 1
    @camickr, thanks, your suggestion worked. It seems that my rusty Java backend also helped me forget OOP principles – Michael Mouer Oct 22 '20 at 17:52
  • @sorifiend, thanks for the @ tip – Michael Mouer Oct 22 '20 at 17:53

0 Answers0