I'm trying to teach myself how to create a GUI using Java swing and Window Builder Pro, after watching several YouTube videos and reading some of the tutorials that I completed, follow these steps.
import javax.swing.JFrame; import javax.swing.JTabbedPane; import javax.swing.JPanel; import javax.swing.SpringLayout; import javax.swing.JTextPane; import javax.swing.JButton; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class JetstreamFrame extends JFrame { private static final long serialVersionUID = 1L; JTabbedPane tabPane; JPanel buttonOnePanel; JPanel buttonTwoPanel; JPanel textDisplayPanel; JTextPane textPane; SpringLayout sl_textDisplayPanel; SpringLayout springLayout; SpringLayout sl_buttonTwoPanel; SpringLayout sl_buttonOnePanel; JButton ButtonTwo; JButton ButtonOne; public JetstreamFrame() { springLayout = new SpringLayout(); getContentPane().setLayout(springLayout); tabPane = new JTabbedPane(JTabbedPane.TOP); setupTabPane(); buttonOnePanel = new JPanel(); sl_buttonOnePanel = new SpringLayout(); setupButtonOnePanel(); ButtonOne = new JButton("Click Here!"); setupButtonOne(); buttonTwoPanel = new JPanel(); sl_buttonTwoPanel = new SpringLayout(); setupButtonTwoPanel(); ButtonTwo = new JButton("Click Here!"); setupButtonTwo(); textDisplayPanel = new JPanel(); sl_textDisplayPanel = new SpringLayout(); setupTextDisplayPanel(); textPane = new JTextPane(); setupTextPane(); } private void setupTabPane() { springLayout.putConstraint(SpringLayout.NORTH, tabPane, 0, SpringLayout.NORTH, getContentPane()); springLayout.putConstraint(SpringLayout.WEST, tabPane, 0, SpringLayout.WEST, getContentPane()); springLayout.putConstraint(SpringLayout.SOUTH, tabPane, -198, SpringLayout.SOUTH, getContentPane()); springLayout.putConstraint(SpringLayout.EAST, tabPane, 484, SpringLayout.WEST, getContentPane()); getContentPane().add(tabPane); } private void setupButtonOnePanel() { tabPane.addTab("Tab One", null, buttonOnePanel, null); buttonOnePanel.setLayout(sl_buttonOnePanel); } private void setupButtonOne() { ButtonOne.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { } }); sl_buttonOnePanel.putConstraint(SpringLayout.NORTH, ButtonOne, 99, SpringLayout.NORTH, buttonOnePanel); sl_buttonOnePanel.putConstraint(SpringLayout.WEST, ButtonOne, 187, SpringLayout.WEST, buttonOnePanel); buttonOnePanel.add(ButtonOne); } private void setupButtonTwoPanel() { tabPane.addTab("Tab Two", null, buttonTwoPanel, null); buttonTwoPanel.setLayout(sl_buttonTwoPanel); } private void setupButtonTwo() { ButtonTwo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { } }); sl_buttonTwoPanel.putConstraint(SpringLayout.NORTH, ButtonTwo, 99, SpringLayout.NORTH, buttonTwoPanel); sl_buttonTwoPanel.putConstraint(SpringLayout.WEST, ButtonTwo, 187, SpringLayout.WEST, buttonTwoPanel); buttonTwoPanel.add(ButtonTwo); } private void setupTextDisplayPanel() { springLayout.putConstraint(SpringLayout.NORTH, textDisplayPanel, 6, SpringLayout.SOUTH, tabPane); springLayout.putConstraint(SpringLayout.WEST, textDisplayPanel, 0, SpringLayout.WEST, getContentPane()); springLayout.putConstraint(SpringLayout.SOUTH, textDisplayPanel, -10, SpringLayout.SOUTH, getContentPane()); springLayout.putConstraint(SpringLayout.EAST, textDisplayPanel, 0, SpringLayout.EAST, getContentPane()); getContentPane().add(textDisplayPanel); textDisplayPanel.setLayout(sl_textDisplayPanel); } private void setupTextPane() { sl_textDisplayPanel.putConstraint(SpringLayout.NORTH, textPane, 0, SpringLayout.NORTH, textDisplayPanel); sl_textDisplayPanel.putConstraint(SpringLayout.WEST, textPane, 0, SpringLayout.WEST, textDisplayPanel); sl_textDisplayPanel.putConstraint(SpringLayout.SOUTH, textPane, 182, SpringLayout.NORTH, textDisplayPanel); sl_textDisplayPanel.putConstraint(SpringLayout.EAST, textPane, 0, SpringLayout.EAST, textDisplayPanel); textDisplayPanel.add(textPane); } public void start() { this.setSize(500, 500); this.setVisible(true); } }
The premise of this code is to create a window with several tabs and a text area at the bottom, which is visible regardless of which tab the user is on. I created a text area, tabs, buttons, as well as button event listeners for this GUI.
Unfortunately, not one of the tutorials that I read showed me how to type anything in the text area. I would like to do something in accordance with
System.out.println();
attached to each of the buttons, and printing this text appears in the text area, but I donβt know how to do it.
I would also like to know if there was an area of ββtext that I created using the scroll bar along the side if the printed text goes beyond the visible frame.