Note that there are some explanatory texts on larger screens.

plurals
  1. POI need a basic simple Java layout method
    primarykey
    data
    text
    <p>I've checked the internet about <code>FlowLayout</code>, <code>Group</code> etc., all with unhelpful examples. I just need a basic way to do a good layout for my Java application. I'll show you my code:</p> <pre><code>import java.awt.*; import javax.swing.*; import javax.swing.border.Border; import javax.swing.border.LineBorder; public class Test1 { //Step1 - Declaring variables private static JFrame myFrame; private static JPanel myPanel; private static JLabel titleLabel=null; private static JLabel logIn=null; private static JLabel username=null; private static JLabel password=null; private static JTextField usernameField=null; private static JPasswordField passwordField=null; private static Color myColor=new Color(0, 102, 204); private static Font myFont11=new Font("Tahoma", 1, 11); private static Font myFont12bold=new Font("Tahoma", Font.BOLD, 12); private static Font myFont11bold=new Font("Tahoma", Font.BOLD, 11); //Step2 - Creating Components public void createComponents() { //Title Label titleLabel=new JLabel("My Program"); titleLabel.setForeground(Color.white); titleLabel.setFont(myFont12bold); //titleLabel.setVisible(false); //hide it or show it //-------------------------------------------------------- logIn=new JLabel("Log in"); logIn.setFont(myFont11bold); logIn.setForeground(Color.white); username=new JLabel("Username"); username.setLabelFor(usernameField); username.setFont(myFont11); username.setForeground(Color.white); password=new JLabel("Password"); password.setLabelFor(passwordField); password.setFont(myFont11); password.setForeground(Color.white); usernameField=new JTextField(10); usernameField.setBorder(new LineBorder(null, 0, false)); passwordField=new JPasswordField(10); passwordField.setBorder(new LineBorder(null, 0, false)); //Panel myPanel=new JPanel(); myPanel.setBackground(myColor); myPanel.add(titleLabel); myPanel.add(logIn); myPanel.add(mySeparator2); myPanel.add(username); myPanel.add(usernameField); myPanel.add(password); myPanel.add(passwordField); //---------------------------------------------------------- //Step3 - Main Function public static void main(String[] arg) { //Frame myFrame=new JFrame(); myFrame.setPreferredSize(new Dimension(400,300));//width:400px, height:300px myFrame.setLocationRelativeTo(null);//to show at center of screen myFrame.setTitle("My Program"); Test1 prog=new Test1(); prog.createComponents(); myFrame.add(myPanel); myFrame.pack();//this alone will not give the frame a size myFrame.setVisible(true); //---------------------------------------------------------------------- } } </code></pre> <p>This is a basic gui which has some labels and some textfields, with the .pack() method they will be shown on the same line, I just need a small simple way to make a good layout</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload