2

I'm trying to show the interface for Matrix Multiplication - A*B*C - using Java concurrency and Using java.swing for the interface.

Meaning there will be 4 windows, 3 input one output. The output matrix cells will change its values dynamically as you enter the inputs in the 3 GUI input windows. I have solved until the logical part of the program but I'm stuck at showing the interface by using swing and binding these two things together?

Which is the best layout to represent matrices in Java swing? And where to start learning Swing for this?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
læran91
  • 283
  • 1
  • 15
  • 2
    Take a look at https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html and especially GridLayout or GridBagLayout. But I think a JTable will be a better approach to display a matrix and edit the values. – René Link Jun 09 '17 at 11:09
  • what about something that could look like a grid.... maybe a gridlayout... – ΦXocę 웃 Пepeúpa ツ Jun 09 '17 at 11:14
  • 2
    There are probably countless ways to do it, but what they will most have in common is, they don't rely on a single layout manager, but instead, use a combination of them (except MigLayout, because it likes to be different) – MadProgrammer Jun 09 '17 at 11:14
  • 1
    *"Meaning there will be 4 windows.."* See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Jun 09 '17 at 11:46
  • [Here](https://stackoverflow.com/a/41621997/2180785)'s an example that uses `GridLayout` as suggested in the comments above. It also adds a custom border to make it look better :) – Frakcool Jun 09 '17 at 12:48
  • Thanks a lot @Thompson that reference helped me a lot. :) – læran91 Jun 10 '17 at 09:54
  • Thank you @Frakcool. U saved my day :) cheers – læran91 Jun 10 '17 at 09:56
  • @Frakcool the code from the link you provided is not working.can you give me a working code layout ? – læran91 Jun 20 '17 at 10:40
  • @KVinodKumar this question was already answered, if you have another question please ask it as a separate question and accept the answer if it solves your problem. In your new question be sure to post a valid [mcve] and explain what is not working, if you copy-paste the code from the answer, it should work – Frakcool Jun 20 '17 at 11:10

1 Answers1

3

I think GridLayout is perfect for your solution:

Grid Layout

I recommend you to learn swing using Oracle's tutorials: Creating a GUI With JFC/Swing

BhalchandraSW
  • 714
  • 5
  • 13
  • how can I show multiple grid layout in same Frame ? – læran91 Jun 20 '17 at 10:41
  • If you want to use more than one layout in your application you should make JPanel that contains your gridLayout and use JPanel on other layout. You can find better explanation in answer for this question: [Link](https://stackoverflow.com/questions/2554684/multiple-layout-managers-in-java) – Ilia Kopysov Jun 20 '17 at 12:37