Results 1 to 2 of 2
  1. #1
    arcelivez is offline Member
    Join Date
    Apr 2011
    Rep Power

    Default JAVA GUI Layout problems...


    so I have a problem with my Swing GUI, I'm trying to create a whiteboard application with a label, then lower the white drawing area (400x250 pixels) and at the bottom 3 buttons, to choose the pen color, well, it doesn't work, what happens is you can just see the three buttons in the gui, so can anyone tell me what I'm doing wrong here?

    The main action happens in the method "public void addComponents(Container pane)"
    Java Code:
    package whiteboard;
    import java.awt.BorderLayout;
    import java.awt.CardLayout;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.Dimension;
    import javax.swing.*;
     * @author arturas
    public class MainWindow {
        JPanel layout;
        private static void showGUI() {
            //Create and set up the window.
            JFrame window = new JFrame("Shared Whiteboard Client");
            //window.setMinimumSize(new Dimension(600,400));
            MainWindow crazy = new MainWindow();
            //Display the window.        
        public void addComponents(Container pane) {
            // It's supposed to be a Whiteboard with a drawing area
            // The Title over the drawing area
            JPanel layoutHeader = new JPanel();
            JLabel label1 = new JLabel("Draw in the white area");
            // The JPanel for the Drawing Area in future to be
            JPanel layoutDrawingArea = new JPanel();
            layoutDrawingArea.setMinimumSize(new Dimension(400, 250));
            // The buttons for choosing pen color
            JButton buttonYellow = new JButton("Yellow");
            JButton buttonGreen = new JButton("Green");
            JButton buttonRed = new JButton("Red");
            // The building of the layout, which doesn't work the way I expect it to...
            JPanel layoutButtons = new JPanel();
            layout = new JPanel(new CardLayout());
            layout.add(layoutHeader, "Please draw in the white area");
            layout.add(layoutDrawingArea, "DrawingArea");
            layout.add(layoutButtons, "Buttons");
            pane.add(layoutHeader, BorderLayout.PAGE_START);
            pane.add(layoutDrawingArea, BorderLayout.CENTER);
            pane.add(layoutButtons, BorderLayout.PAGE_END);
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
    Any ideas?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default Re: JAVA GUI Layout problems...

    I don't understand your use of a CardLayout-using JPanel and adding components to it. It seems like that it serves no purpose, and worse that it is messing things up so that your other components won't show; so you'll have to explain your rationale behind this. Also, most layout managers respect a component's preferedSize, so this property will likely have to be set on your drawing area. I assume that you're going to use MouseMotionListener and MouseListener (combined as a MouseAdapter) eventually, correct?

Similar Threads

  1. Replies: 13
    Last Post: 12-06-2010, 05:57 AM
  2. Keyboard Layout Problems
    By FrederikNS in forum Eclipse
    Replies: 0
    Last Post: 10-28-2008, 04:03 PM
  3. JPanel / layout problems
    By Warhorsei in forum AWT / Swing
    Replies: 4
    Last Post: 06-04-2008, 05:26 AM
  4. Java GUI layout
    By nick2price in forum New To Java
    Replies: 2
    Last Post: 05-27-2008, 09:42 PM
  5. Use the Layout in java
    By lenny in forum AWT / Swing
    Replies: 2
    Last Post: 07-26-2007, 07:20 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