mixing awt and swing in GUI programming using Java

前端 未结 1 896
粉色の甜心
粉色の甜心 2021-01-03 10:40

I read on SO that mixing awt and swing is not really a good approach for GUI programming in Java. I cannot though, find any examples which does not use some awt components w

相关标签:
1条回答
  • 2021-01-03 10:53

    You'll use the AWT layouts, action listeners and so on when using Swing - this is ok and by design, the Swing framework builds on AWT in this respect. This is in contrast to JavaFX which is a complete GUI framework in its own right, and contains its own layouts, event handlers and so on.

    What you should avoid if possible is mixing the actual components you place in the GUI - using a JButton inside a Frame (rather than a JFrame) for example, or using a Button and JButton side by side.

    There are some cases where it's necessary - using VLCJ in a Swing application for instance requires a heavyweight (AWT) canvas if you want to use a normal embedded video player. However, without a good use case like the above, it's something that should be avoided.

    0 讨论(0)
提交回复
热议问题