├── src └── main │ ├── resources │ └── application.properties │ └── java │ └── ca │ └── purpleowl │ └── examples │ └── swing │ ├── jpa │ ├── repository │ │ └── JournalEntryRepository.java │ └── model │ │ └── JournalEntry.java │ ├── SpringBootSwingApplication.java │ ├── SpringBootSwingCommandLineRunner.java │ └── ui │ ├── view │ ├── JournalEntryView.form │ ├── MainView.form │ ├── JournalEntryView.java │ └── MainView.java │ └── controller │ ├── MainController.java │ └── JournalEntryController.java ├── .gitignore ├── README.md └── pom.xml /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:h2:mem: 2 | spring.datasource.driver-class-name=org.h2.Driver 3 | -------------------------------------------------------------------------------- /src/main/java/ca/purpleowl/examples/swing/jpa/repository/JournalEntryRepository.java: -------------------------------------------------------------------------------- 1 | package ca.purpleowl.examples.swing.jpa.repository; 2 | 3 | import ca.purpleowl.examples.swing.jpa.model.JournalEntry; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | import java.util.List; 7 | 8 | public interface JournalEntryRepository extends CrudRepository { 9 | List findAllByOrderByEntryTimeDesc(); 10 | } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | mvnw 4 | mvnw.cmd 5 | 6 | ### STS ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 16 | *.iws 17 | *.iml 18 | *.ipr 19 | ======= 20 | # Compiled class file 21 | *.class 22 | 23 | # Log file 24 | *.log 25 | 26 | # BlueJ files 27 | *.ctxt 28 | 29 | # Mobile Tools for Java (J2ME) 30 | .mtj.tmp/ 31 | 32 | # Package Files # 33 | *.jar 34 | *.war 35 | *.ear 36 | *.zip 37 | *.tar.gz 38 | *.rar 39 | -------------------------------------------------------------------------------- /src/main/java/ca/purpleowl/examples/swing/SpringBootSwingApplication.java: -------------------------------------------------------------------------------- 1 | package ca.purpleowl.examples.swing; 2 | 3 | import org.springframework.boot.WebApplicationType; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.builder.SpringApplicationBuilder; 6 | 7 | /** 8 | * This is the Spring Boot Application class. This is where we make sure we're NOT running in Headless mode and that 9 | * the WebApplicationType is set to NONE. 10 | */ 11 | @SpringBootApplication 12 | public class SpringBootSwingApplication { 13 | 14 | public static void main(String[] args) { 15 | new SpringApplicationBuilder(SpringBootSwingApplication.class) 16 | .headless(false) 17 | .web(WebApplicationType.NONE) 18 | .run(args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/ca/purpleowl/examples/swing/SpringBootSwingCommandLineRunner.java: -------------------------------------------------------------------------------- 1 | package ca.purpleowl.examples.swing; 2 | 3 | import ca.purpleowl.examples.swing.ui.controller.MainController; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.CommandLineRunner; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.awt.*; 9 | 10 | /** 11 | * This CommandLineRunner fires off at runtime and boots up our GUI. 12 | */ 13 | @Component 14 | public class SpringBootSwingCommandLineRunner implements CommandLineRunner { 15 | private final MainController controller; 16 | 17 | @Autowired 18 | public SpringBootSwingCommandLineRunner(MainController controller) { 19 | this.controller = controller; 20 | } 21 | 22 | 23 | @Override 24 | public void run(String... args) { 25 | //This boots up the GUI. 26 | EventQueue.invokeLater(() -> controller.setVisible(true)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-swing 2 | A Java app with Swing?! Have we travelled in time back to the 90's?? We sure have for this blog post. Join me for a walk down memory lane with some modern twists. 3 | 4 | 5 | ## Purpose 6 | Sometimes you have functionality that you need to make a really simple form or series of forms to access/utilize. Sometimes you have a restrictive environment in which you need some tools running with some kind of minimal UI. Anyways, I found myself in a situation that needed this, and I thought I'd share. 7 | 8 | This also pointed me down the road to a plugin that was effectively broken by the introduction of lambdas. Some day, I might take that on!! Because of that broken plugin, there's a step in the middle where we have to use the IDE to generate some code. This is done with IntelliJ IDEA, because it's an amazing IDE. I wish I could say I'm a "paid shill," but I'm not. I'm just a fan-boy. 9 | 10 | This creates a Spring Boot application without an embedded web server, running a simple H2 database. It saves some data, reads some data, and serves as a good launching point for this sort of thing. I should underline the fact that Swing UI just sucks in general... but sometimes you have a limited toolset! 11 | 12 | 13 | ## How to Build it 14 | For the most part, you just build with the typical maven `install` goal, but if you make any changes to the UI in the GUI Designer, you're going to have to build through Intellij (`Command + F9` on a Mac, `CTRL + F9` on Windows and probably on Linux, too). 15 | 16 | ## How to Run it 17 | This is a Spring Boot application, so your typical `spring-boot:run` maven goal will do the trick. Since it's using an in-memory database, there's no additional setup required for that. 18 | -------------------------------------------------------------------------------- /src/main/java/ca/purpleowl/examples/swing/jpa/model/JournalEntry.java: -------------------------------------------------------------------------------- 1 | package ca.purpleowl.examples.swing.jpa.model; 2 | 3 | import org.hibernate.annotations.GenericGenerator; 4 | 5 | import javax.persistence.*; 6 | import java.time.LocalDateTime; 7 | import java.time.format.DateTimeFormatter; 8 | 9 | @Entity 10 | @Table 11 | public class JournalEntry { 12 | @Id 13 | @GeneratedValue(generator = "increment") 14 | @GenericGenerator(name = "increment", strategy = "increment") 15 | private Long id; 16 | 17 | @Column 18 | private String entry; 19 | 20 | @Column 21 | private LocalDateTime entryTime; 22 | 23 | public JournalEntry() {} 24 | 25 | public Long getId() { 26 | return id; 27 | } 28 | 29 | public JournalEntry setId(Long id) { 30 | this.id = id; 31 | return this; 32 | } 33 | 34 | public String getEntry() { 35 | return entry; 36 | } 37 | 38 | public JournalEntry setEntry(String entry) { 39 | this.entry = entry; 40 | return this; 41 | } 42 | 43 | public LocalDateTime getEntryTime() { 44 | return entryTime; 45 | } 46 | 47 | public JournalEntry setEntryTime(LocalDateTime entryTime) { 48 | this.entryTime = entryTime; 49 | return this; 50 | } 51 | 52 | /** 53 | * We override this so that the JList displays the date. There are other ways to do this, but this is one option. 54 | * 55 | * @return The String value of the Journal Entry timestamp. 56 | */ 57 | @Override 58 | public String toString() { 59 | return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(entryTime); 60 | } 61 | 62 | public boolean isNew() { 63 | return id == null; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/ca/purpleowl/examples/swing/ui/view/JournalEntryView.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 |
42 | -------------------------------------------------------------------------------- /src/main/java/ca/purpleowl/examples/swing/ui/view/MainView.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
51 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | ca.purpleowl.examples.swing 7 | spring-boot-swing 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-boot-swing 12 | It's a retro throwback with a modern twist. 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.0.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 9 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-data-jpa 36 | 37 | 38 | 39 | com.h2database 40 | h2 41 | 42 | 43 | 45 | 46 | com.intellij 47 | forms_rt 48 | 7.0.3 49 | 50 | 51 | 52 | org.hibernate 53 | hibernate-java8 54 | 5.1.0.Final 55 | 56 | 57 | 59 | 60 | org.springframework.boot 61 | spring-boot-configuration-processor 62 | true 63 | 64 | 65 | 66 | 67 | javax.xml.bind 68 | jaxb-api 69 | 2.3.0 70 | 71 | 72 | 73 | org.springframework.boot 74 | spring-boot-starter-test 75 | test 76 | 77 | 78 | 79 | 80 | 81 | 82 | org.springframework.boot 83 | spring-boot-maven-plugin 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /src/main/java/ca/purpleowl/examples/swing/ui/controller/MainController.java: -------------------------------------------------------------------------------- 1 | package ca.purpleowl.examples.swing.ui.controller; 2 | 3 | import ca.purpleowl.examples.swing.jpa.model.JournalEntry; 4 | import ca.purpleowl.examples.swing.jpa.repository.JournalEntryRepository; 5 | import ca.purpleowl.examples.swing.ui.view.MainView; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Controller; 8 | 9 | import javax.swing.*; 10 | import java.util.Optional; 11 | 12 | /** 13 | * This is the main view of the application. If it gets closed, then the application stops. 14 | */ 15 | @Controller 16 | public class MainController extends JFrame { 17 | private final MainView view; 18 | private final JournalEntryRepository repo; 19 | private final JournalEntryController journalEntryController; 20 | 21 | /** 22 | * This autowired constructor automagically receives reference to both a JournalEntryRepository (for access to the 23 | * persistence mechanism) and a JournalEntryController for writing or displaying JournalEntries. 24 | * 25 | * @param journalEntryRepository - A JournalEntryRepository instance provided via Autowiring. 26 | * @param journalEntryController - A JournalEntryController provided via Autowiring. 27 | */ 28 | @Autowired 29 | public MainController(JournalEntryRepository journalEntryRepository, JournalEntryController journalEntryController) { 30 | super("What a hideous application!"); 31 | 32 | this.repo = journalEntryRepository; 33 | this.journalEntryController = journalEntryController.setCaller(this); 34 | 35 | this.view = new MainView() { 36 | @Override 37 | protected void newEntryButtonClicked() { 38 | doNewEntry(); 39 | } 40 | 41 | @Override 42 | protected void viewEntryButtonClicked() { 43 | doViewEntry(); 44 | } 45 | }; 46 | 47 | this.setContentPane(view.$$$getRootComponent$$$()); 48 | this.setDefaultCloseOperation(EXIT_ON_CLOSE); 49 | 50 | view.setJournalEntryListContent(repo.findAllByOrderByEntryTimeDesc().toArray()); 51 | 52 | this.pack(); 53 | } 54 | 55 | private void doNewEntry() { 56 | journalEntryController.setModel(new JournalEntry()); 57 | journalEntryController.setVisible(true); 58 | } 59 | 60 | private void doViewEntry() { 61 | Long id = ((JournalEntry)view.getSelectedEntry()).getId(); 62 | Optional maybeEntry = repo.findById(id); 63 | journalEntryController.setModel(maybeEntry.orElse(new JournalEntry())); 64 | journalEntryController.setVisible(true); 65 | } 66 | 67 | /** 68 | * I hook the refresh of the JList up to the validate method. Then you can call it from another view without 69 | * having to actually know the implementation under the hood. It's just a JFrame that you're validating. 70 | */ 71 | @Override 72 | public void validate() { 73 | super.validate(); 74 | view.setJournalEntryListContent(repo.findAllByOrderByEntryTimeDesc().toArray()); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/ca/purpleowl/examples/swing/ui/view/JournalEntryView.java: -------------------------------------------------------------------------------- 1 | package ca.purpleowl.examples.swing.ui.view; 2 | 3 | import com.intellij.uiDesigner.core.GridConstraints; 4 | import com.intellij.uiDesigner.core.GridLayoutManager; 5 | 6 | import javax.swing.*; 7 | import java.awt.*; 8 | 9 | /** 10 | * This view is for displaying or writing a Journal Entry. Just a simple JTextArea with an action button for either 11 | * saving the record or closing the view. 12 | */ 13 | public abstract class JournalEntryView { 14 | private JPanel entryPanel; 15 | private JTextArea journalEntry; 16 | private JButton actionButton; 17 | 18 | protected JournalEntryView() { 19 | actionButton.addActionListener(e -> actionButtonClicked()); 20 | } 21 | 22 | protected abstract void actionButtonClicked(); 23 | 24 | public void setText(String text) { 25 | journalEntry.setText(text); 26 | } 27 | 28 | public String getText() { 29 | return journalEntry.getText(); 30 | } 31 | 32 | /** 33 | * Enable View Mode, which just makes the JTextArea non-editable and sets the text of the Action Button to "Close." 34 | */ 35 | public void viewMode() { 36 | journalEntry.setEditable(false); 37 | actionButton.setText("Close"); 38 | } 39 | 40 | public void writeMode() { 41 | journalEntry.setEditable(true); 42 | actionButton.setText("Save"); 43 | } 44 | 45 | { 46 | // GUI initializer generated by IntelliJ IDEA GUI Designer 47 | // >>> IMPORTANT!! <<< 48 | // DO NOT EDIT OR ADD ANY CODE HERE! 49 | $$$setupUI$$$(); 50 | } 51 | 52 | /** 53 | * Method generated by IntelliJ IDEA GUI Designer 54 | * >>> IMPORTANT!! <<< 55 | * DO NOT edit this method OR call it in your code! 56 | * 57 | * @noinspection ALL 58 | */ 59 | private void $$$setupUI$$$() { 60 | entryPanel = new JPanel(); 61 | entryPanel.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1)); 62 | entryPanel.setPreferredSize(new Dimension(500, 450)); 63 | entryPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Ugly Journal Entry")); 64 | journalEntry = new JTextArea(); 65 | entryPanel.add(journalEntry, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW, null, new Dimension(150, 50), null, 0, false)); 66 | final JPanel panel1 = new JPanel(); 67 | panel1.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1)); 68 | entryPanel.add(panel1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); 69 | actionButton = new JButton(); 70 | actionButton.setText("Button"); 71 | panel1.add(actionButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); 72 | } 73 | 74 | /** 75 | * @noinspection ALL 76 | */ 77 | public JComponent $$$getRootComponent$$$() { 78 | return entryPanel; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/ca/purpleowl/examples/swing/ui/controller/JournalEntryController.java: -------------------------------------------------------------------------------- 1 | package ca.purpleowl.examples.swing.ui.controller; 2 | 3 | import ca.purpleowl.examples.swing.jpa.model.JournalEntry; 4 | import ca.purpleowl.examples.swing.jpa.repository.JournalEntryRepository; 5 | import ca.purpleowl.examples.swing.ui.view.JournalEntryView; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Controller; 8 | 9 | import javax.swing.*; 10 | import java.time.LocalDateTime; 11 | 12 | /** 13 | * This this controller takes care of displaying and potentially saving a JournalEntry entity. The preceding 14 | * Controller actually gets to set the model. 15 | */ 16 | @Controller 17 | public class JournalEntryController extends JFrame { 18 | private final JournalEntryView view; 19 | private final JournalEntryRepository repo; 20 | private JournalEntry model; 21 | private JFrame caller; 22 | 23 | /** 24 | * This constructor is autowired and automagically gets an instance of JournalEntryRepository to allow it to save 25 | * records to the persistence mechanism when appropriate. 26 | * 27 | * @param journalEntryRepository - An instance of JournalEntryRepository supplied via Autowiring or Mocking. 28 | */ 29 | @Autowired 30 | public JournalEntryController(JournalEntryRepository journalEntryRepository) { 31 | super("Another hideous screen?!"); 32 | this.repo = journalEntryRepository; 33 | this.view = new JournalEntryView() { 34 | @Override 35 | protected void actionButtonClicked() { 36 | doAction(); 37 | } 38 | }; 39 | this.setContentPane(view.$$$getRootComponent$$$()); 40 | this.setDefaultCloseOperation(HIDE_ON_CLOSE); 41 | this.pack(); 42 | } 43 | 44 | /** 45 | * We allow for two potential actions. If the JournalEntry is new, then the action is Save. If the JournalEntry 46 | * already exists in the database, we just display it and close the window when we're done. 47 | */ 48 | private void doAction() { 49 | if(model.isNew()) { 50 | model.setEntry(view.getText()); 51 | model.setEntryTime(LocalDateTime.now()); 52 | repo.save(model); 53 | } 54 | this.setVisible(false); 55 | model = null; 56 | view.setText(""); 57 | caller.validate(); 58 | } 59 | 60 | /** 61 | * Set the model and manipulate the view appropriately. If the model is New, then set the View into Write Mode. If 62 | * it isn't new, set it in Write mode. 63 | * 64 | * @param model - The JournalEntry object to be displayed and - maybe - edited. 65 | */ 66 | public void setModel(JournalEntry model) { 67 | this.model = model; 68 | if(model.isNew()) { 69 | view.setText(""); 70 | view.writeMode(); 71 | } else { 72 | view.setText(model.getEntry()); 73 | view.viewMode(); 74 | } 75 | } 76 | 77 | /** 78 | * Set the View calling to this one, so that we can get it to refresh after we save an entry to the database. 79 | * 80 | * @param caller - A JFrame that instantiated this one. 81 | * @return A reference to this instance of JournalEntryController. This is a builder method, because I like them. 82 | */ 83 | public JournalEntryController setCaller(JFrame caller) { 84 | this.caller = caller; 85 | return this; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/ca/purpleowl/examples/swing/ui/view/MainView.java: -------------------------------------------------------------------------------- 1 | package ca.purpleowl.examples.swing.ui.view; 2 | 3 | import com.intellij.uiDesigner.core.GridConstraints; 4 | import com.intellij.uiDesigner.core.GridLayoutManager; 5 | 6 | import javax.swing.*; 7 | import java.awt.*; 8 | 9 | /** 10 | * We make this view abstract so that we can implement actions without having to know anything going on under 11 | * the hood. Anything to do with manipulating the actual View is done here, while manipulating the Model is done 12 | * in the Controller, which makes a concrete implementation of this view. 13 | * 14 | * Most of the code here gets generated by IntelliJ IDEA's GUI Designer. 15 | */ 16 | public abstract class MainView { 17 | private JPanel mainPanel; 18 | private JList journalEntryList; 19 | private JButton newEntryButton; 20 | private JButton viewEntryButton; 21 | 22 | protected abstract void newEntryButtonClicked(); 23 | 24 | protected abstract void viewEntryButtonClicked(); 25 | 26 | public Object getSelectedEntry() { 27 | return journalEntryList.getSelectedValue(); 28 | } 29 | 30 | @SuppressWarnings("unchecked") 31 | public void setJournalEntryListContent(Object[] contents) { 32 | journalEntryList.setListData(contents); 33 | } 34 | 35 | protected MainView() { 36 | //"event" is definitely not used anywhere, in case you were trying to figure that out. 37 | newEntryButton.addActionListener(event -> newEntryButtonClicked()); 38 | viewEntryButton.addActionListener(event -> viewEntryButtonClicked()); 39 | } 40 | 41 | { 42 | // GUI initializer generated by IntelliJ IDEA GUI Designer 43 | // >>> IMPORTANT!! <<< 44 | // DO NOT EDIT OR ADD ANY CODE HERE! 45 | $$$setupUI$$$(); 46 | } 47 | 48 | /** 49 | * Method generated by IntelliJ IDEA GUI Designer 50 | * >>> IMPORTANT!! <<< 51 | * DO NOT edit this method OR call it in your code! 52 | * 53 | * @noinspection ALL 54 | */ 55 | private void $$$setupUI$$$() { 56 | mainPanel = new JPanel(); 57 | mainPanel.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1)); 58 | mainPanel.setMinimumSize(new Dimension(420, 420)); 59 | mainPanel.setPreferredSize(new Dimension(420, 420)); 60 | mainPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Ugly Journal")); 61 | journalEntryList = new JList(); 62 | mainPanel.add(journalEntryList, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_WANT_GROW, null, new Dimension(150, 50), null, 0, false)); 63 | final JPanel panel1 = new JPanel(); 64 | panel1.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1)); 65 | mainPanel.add(panel1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); 66 | newEntryButton = new JButton(); 67 | newEntryButton.setText("New Entry"); 68 | panel1.add(newEntryButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); 69 | viewEntryButton = new JButton(); 70 | viewEntryButton.setText("View Entry"); 71 | panel1.add(viewEntryButton, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); 72 | } 73 | 74 | /** 75 | * @noinspection ALL 76 | */ 77 | public JComponent $$$getRootComponent$$$() { 78 | return mainPanel; 79 | } 80 | } 81 | --------------------------------------------------------------------------------