Advertisement
Guest User

Untitled

a guest
Jan 12th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 2.56 KB | None | 0 0
  1. import groovy.swing.SwingBuilder
  2. import javax.swing.BoxLayout
  3. import javax.swing.JFrame
  4. import javax.swing.JOptionPane
  5. import java.awt.BorderLayout
  6. import java.awt.FlowLayout
  7. import java.awt.GridLayout
  8. import static javax.swing.WindowConstants.*
  9. import static javax.swing.JOptionPane.showInputDialog
  10.  
  11. final layoutsList = ['FlowLayout', 'BorderLayout', 'GridLayout', 'BoxLayout']
  12. final buttonList = ['Button1', 'Button2', 'Button3', 'Button4', 'Button5']
  13. swing = new SwingBuilder()
  14. JFrame f = new JFrame()
  15. def answer = showInputDialog(f,"Choose layout",
  16.         "Layouts",
  17.         JOptionPane.QUESTION_MESSAGE, null, layoutsList as Object[], 'FlowLayout'
  18.  
  19. )
  20. def borderLayoutConstraints = [ 'West', 'North', 'East', 'South', 'Center']
  21. Integer i = 0
  22.  
  23. swing.edt {
  24.     lookAndFeel('nimbus')
  25.  
  26.     frame(title: answer, pack: true, visible: true,
  27.             defaultCloseOperation: EXIT_ON_CLOSE) {
  28.         switch (answer){
  29.             case 'BorderLayout':
  30.                 vbox() {
  31.                     panel(layout: new FlowLayout()) {
  32.                         label(text: answer)
  33.                     }
  34.                     panel(layout: new BorderLayout()) {
  35.                         buttonList.each {
  36.                             button(it, constraints: borderLayoutConstraints[i])
  37.                             i++
  38.                         }
  39.                     }
  40.                 }
  41.                 break
  42.             case 'FlowLayout':
  43.                 panel(layout: new FlowLayout()){
  44.                     label(text: answer)
  45.                     buttonList.each {
  46.                        button(text:  it)
  47.                     }
  48.                 }
  49.                 break
  50.             case 'GridLayout':
  51.                 vbox() {
  52.                     panel(layout: new FlowLayout()){
  53.                         label(text: answer)
  54.                     }
  55.                     panel(layout: new GridLayout(2, 3)) {
  56.                         buttonList.each {
  57.                             button(text: it)
  58.                         }
  59.                     }
  60.                 }
  61.                 break
  62.             case 'BoxLayout':
  63.                 vbox() {
  64.                     panel(layout: new FlowLayout()){
  65.                         label(text: answer)
  66.                     }
  67.                     panel() {
  68.                         boxLayout(axis: BoxLayout.Y_AXIS)
  69.                         buttonList.each {
  70.                             button(text: it)
  71.                         }
  72.                     }
  73.                 }
  74.                 break
  75.             default: break
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement