From 1fafab78b6641315f9545fdf0e97dd33f21127b7 Mon Sep 17 00:00:00 2001 From: Kristian Knarvik Date: Fri, 26 Jan 2018 22:17:36 +0100 Subject: [PATCH] Nicer but probably less cross-compatible GUI --- .../serverlauncher/userinterface/GUI.java | 74 +++++++++++++++++-- 1 file changed, 66 insertions(+), 8 deletions(-) diff --git a/src/net/knarcraft/serverlauncher/userinterface/GUI.java b/src/net/knarcraft/serverlauncher/userinterface/GUI.java index 19239ae..88bf151 100644 --- a/src/net/knarcraft/serverlauncher/userinterface/GUI.java +++ b/src/net/knarcraft/serverlauncher/userinterface/GUI.java @@ -1,6 +1,7 @@ package net.knarcraft.serverlauncher.userinterface; import javax.swing.*; +import javax.swing.border.EmptyBorder; import java.awt.*; /** @@ -12,6 +13,18 @@ import java.awt.*; */ public class GUI { public GUI() { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (UnsupportedLookAndFeelException e) { + e.printStackTrace(); + } + JFrame frame = new JFrame("Minecraft server launcher"); ImageIcon img = new ImageIcon("files/GUIIcon.png"); frame.setIconImage(img.getImage()); @@ -64,15 +77,49 @@ public class GUI { frame.setJMenuBar(menu); JTabbedPane tabs = new JTabbedPane(SwingConstants.TOP); - JPanel panel = new JPanel(); - JLabel basicControls = new JLabel("Basic controls"); - JButton sendStart = new JButton("Start servers"); - JButton sendStop = new JButton("Stop servers"); + //First tab + JPanel controlPanel = new JPanel(); + controlPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); + GroupLayout controlLayout = new GroupLayout(controlPanel); + controlPanel.setLayout(controlLayout); + JLabel basicControls = customLabel("Basic controls"); + JButton sendStart = customButton("Start servers"); + JButton sendStop = customButton("Stop servers"); + JButton backup = customButton("Backup"); + JButton viewConsole = customButton("View server consoles"); + JLabel profile = customLabel("Profile"); + + controlLayout.setVerticalGroup( + controlLayout.createSequentialGroup() + .addGroup(controlLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(basicControls)) + .addGroup(controlLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(sendStart) + .addComponent(sendStop) + .addComponent(backup) + .addComponent(viewConsole)) + .addGroup(controlLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(profile))); + + controlLayout.setHorizontalGroup( + controlLayout.createSequentialGroup() + .addGroup(controlLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(basicControls) + .addComponent(profile) + .addComponent(sendStart)) + .addGroup(controlLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(sendStop)) + .addGroup(controlLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(backup)) + .addGroup(controlLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(viewConsole))); + + + tabs.addTab("Control panel", null, controlPanel, "Basic server controls"); + + JPanel serversPanel = new JPanel(); + tabs.addTab("Control servers", null, serversPanel, "Easy server commands"); - panel.add(basicControls); - panel.add(sendStart); - panel.add(sendStop); - tabs.addTab("Basic controls", null, panel, "Basic server controls"); frame.add(tabs); // TODO: Finish gui @@ -84,4 +131,15 @@ public class GUI { Insets insets = frame.getInsets(); frame.setSize(450 + 2 * insets.left, 170 + insets.top + insets.bottom); } + + private JButton customButton(String text) { + JButton button = new JButton(text); + button.setMargin(new Insets(3,5,3,5)); + return button; + } + private JLabel customLabel(String text) { + JLabel label = new JLabel(text); + label.setBorder(new EmptyBorder(1, 2, 1, 0)); + return label; + } }