// Display a JFrame // Note, this will not be shown in the notebook, but will be shown as a floating window. // To render the JFrame inline, you will need to pull out the content panenl of the JFrame // but be aware that the size might be wrong. import java.awt.Color import java.awt.Dimension import java.awt.GraphicsConfiguration import java.awt.RenderingHints import java.awt.image.BufferedImage import java.io.File import javax.swing.* val frame = JFrame("Color Changer") frame.defaultCloseOperation = JFrame.DISPOSE_ON_CLOSE // EXIT_ON_CLOSE doesn't work frame.preferredSize = Dimension(300, 200) val panel = JPanel() //panel.preferredSize = Dimension(300, 200) val button1 = JButton("Button 1") val button2 = JButton("Button 2") val button3 = JButton("Button 3") button1.addActionListener { panel.background = Color.RED } button2.addActionListener { panel.background = Color.GREEN } button3.addActionListener { panel.background = Color.BLUE } panel.add(button1) panel.add(button2) panel.add(button3) frame.add(panel) frame.pack() frame.isVisible = true frame // Frames are shown outside IDEA // Display a JDialog // Note, this will not be shown in the notebook, but will be shown as a floating window. // To render the JDialog inline, you will need to pull out the content panenl of the JDialog // but be aware that the size might be wrong. val dialog = JDialog() dialog.defaultCloseOperation = JFrame.DISPOSE_ON_CLOSE // EXIT_ON_CLOSE doesn't work dialog.preferredSize = Dimension(300, 200) val panel = JPanel() //panel.preferredSize = Dimension(300, 200) val button1 = JButton("Button 1") val button2 = JButton("Button 2") val button3 = JButton("Button 3") button1.addActionListener { panel.background = Color.RED } button2.addActionListener { panel.background = Color.GREEN } button3.addActionListener { panel.background = Color.BLUE } panel.add(button1) panel.add(button2) panel.add(button3) dialog.add(panel) dialog.pack() dialog.isVisible = true dialog // Dialogs are shown outside IDEA // Display a JPanel // JPanels will be displayed inline in import java.awt.Color import java.awt.Dimension import java.awt.GraphicsConfiguration import java.awt.RenderingHints import java.awt.image.BufferedImage import java.io.File import javax.swing.* val panel = JPanel() panel.size = Dimension(300, 200) panel.preferredSize = Dimension(300, 200) val button1 = JButton("Button 2") button1.size = Dimension(100, 50) panel.add(button1) panel.isVisible = true panel // Panels are shown inside IDEA