Results 1 to 3 of 3
  1. #1
    Forum22 is offline Member
    Join Date
    Nov 2016
    Posts
    2
    Rep Power
    0

    Default Grid layout issue URGENT

    //there is an issue with panel.add and the panel orientation
    // if you would be so kind could you rewrite the code where the issues are
    //the problem may be that they are all in one class or there may be a naming issue which causes the red underneath the "add" in panel.add and the setComponentOrientation section.
    //the issues are from line 27-72 thats where my problem is


    Java Code:
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.ComponentOrientation;
    import java.awt.GridLayout;
    import java.awt.PopupMenu;
    import java.awt.event.ActionEvent;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.util.Arrays;
    import java.util.logging.Logger;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JPasswordField;
    import javax.swing.JTextField;
    import javax.swing.SwingConstants;
    import javax.swing.SwingUtilities;
    
    public class TestFrame extends JFrame {
    public static final long serialVersionUID = 1L;
    public static final Logger LOG = Logger.getLogger(TestFrame.class.getName());
    public static final Logger LOGGER = Logger.getLogger(TestFrame.class.getName());
    public static Object panel;
    
    public static void main(String[] args) {
    SwingUtilities.invokeLater(() -> {
    JFrame frame;
    frame = new TestFrame();
    frame.getContentPane().setBackground(Color.BLACK);
    frame.setTitle("Logged In");
    frame.setSize(200,200);
    JButton jbtOkay = new JButton("Next");
    jbtOkay.setLocation(1000,70);
    jbtOkay.setSize(50,50);
    JPanel newPanel = new JPanel();
    newPanel.add(jbtOkay);
    //issue when changing the size and location on the button on the second window. Button does not change size or location
    
    //grid layout for 2nd window
    JFrame frame = new JFrame("Grid Layout");
    frame.pack();
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.setSize(300, 400);
    panel.JLabel (new GridLayout(3, 4, 5, 10)); //rows, columns, horizontal gap, virtical gap
    JLabel labell= new JLabel("Hello1");
    JLabel label2= new JLabel("Hello2");
    JLabel label3= new JLabel("Hello3");
    JLabel label4= new JLabel("Hello4");
    JLabel label5= new JLabel("Hello5");
    JLabel label6= new JLabel("Hello6");
    JLabel label7= new JLabel("Hello7");
    JLabel label8= new JLabel("Hello8");
    JLabel label9= new JLabel("Hello9"); 
    panel.setComponentOrientation(ComponentOrientation .LEFT_TO_RIGHT); //orders which way the labels 1-9 is inputted 
    panel.add(label1);
    panel.add(label2);
    panel.add(label3);
    panel.add(label4);
    panel.add(label5);
    panel.add(label6);
    panel.add(label7);
    panel.add(label8);
    panel.add(label9);
    
    frame.add((PopupMenu) panel); 
    //the issue is trying to get the grid layout panels on the second window which pops up but there are issue when i typed the code. I dont know how to assign the code to the 2nd layout.
    
    
    frame.add(newPanel);
    
    
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.setLocationRelativeTo(null);
    frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    
    });
    }
    
    public PassWordDialog passDialog;
    
    public TestFrame() {
    passDialog = new PassWordDialog(this, true);
    passDialog.setVisible(true);
    }
    
    public PassWordDialog getPassDialog() {
    return passDialog;
    }
    public void setPassDialog(PassWordDialog passDialog) {
    this.passDialog = passDialog;
    }
    
    }
    
    @SuppressWarnings("Serial")
    class PassWordDialog extends JDialog {
    public static final Logger LOG = Logger.getLogger(PassWordDialog.class.getName());
    public static final long serialVersionUID = 1L;
    
    public final JLabel jlblUsername = new JLabel("Username");
    public final JLabel jlblPassword = new JLabel("Password");
    
    public final JTextField jtfUsername = new JTextField(15);
    public final JPasswordField jpfPassword = new JPasswordField();
    
    public final JButton jbtOk = new JButton("Login");
    public final JButton jbtCancel = new JButton("Cancel");
    
    
    
    public final JLabel jlblStatus = new JLabel(" ");
    
    PassWordDialog() {
    this(null, true);
    }
    
    PassWordDialog(final JFrame parent, boolean modal) {
    super(parent, modal);
    
    JPanel p3 = new JPanel(new GridLayout(2, 1));
    p3.add(jlblUsername);
    p3.add(jlblPassword);
    
    JPanel p4 = new JPanel(new GridLayout(2, 1));
    p4.add(jtfUsername);
    p4.add(jpfPassword);
    
    JPanel p1 = new JPanel();
    p1.add(p3);
    p1.add(p4);
    
    JPanel p2 = new JPanel();
    p2.add(jbtOk);
    p2.add(jbtCancel);
    
    JPanel p5 = new JPanel(new BorderLayout());
    p5.add(p2, BorderLayout.CENTER);
    p5.add(jlblStatus, BorderLayout.NORTH);
    jlblStatus.setForeground(Color.RED);
    jlblStatus.setHorizontalAlignment(SwingConstants.C ENTER);
    
    
    setLayout(new BorderLayout());
    add(p1, BorderLayout.CENTER);
    add(p5, BorderLayout.SOUTH);
    pack();
    
    
    setLocationRelativeTo(null);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    
    addWindowListener(new WindowAdapter() { 
    @Override
    public void windowClosing(WindowEvent e) { 
    System.exit(0); 
    } 
    });
    
    
    jbtOk.addActionListener((ActionEvent e) -> {
    if (Arrays.equals("mete".toCharArray(), jpfPassword.getPassword())
    && "mete".equals(jtfUsername.getText())) {
    parent.setVisible(true);
    setVisible(false);
    } else {
    jlblStatus.setText("Invalid username or password");
    }});
    jbtCancel.addActionListener((ActionEvent e) -> {
    setVisible(false);
    parent.dispose();
    System.exit(0);
    });
    
    }
    }

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,991
    Rep Power
    8

    Default Re: Grid layout issue URGENT

    panel.JLabel (line 47) is not a valid Java statement. What you trying to do there?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Grid layout issue URGENT

    Please don't start more than one thread for the same topic. This thread closed.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Grid layout issue URGENT
    By Forum22 in forum New To Java
    Replies: 2
    Last Post: 11-12-2016, 09:11 PM
  2. using grid layout
    By droidus in forum AWT / Swing
    Replies: 8
    Last Post: 07-03-2013, 09:06 PM
  3. Grid Layout change layout alignment of control s
    By rellicott in forum SWT / JFace
    Replies: 1
    Last Post: 02-13-2012, 05:11 PM
  4. Grid Layout with paintComponent
    By mp06677 in forum New To Java
    Replies: 1
    Last Post: 03-06-2010, 01:20 PM
  5. Help with Grid Layout
    By coco in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 08:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •