Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: JFrame, frame's title doesnt appear.

  1. #1
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default JFrame, frame's title doesnt appear.

    import SwingGUI_Applications.JSliderSample2;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JSlider;
    import javax.swing.JButton;
    import javax.swing.Action;
    import javax.swing.AbstractAction;
    import javax.swing.SwingConstants;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ChangeListener;
     
    import java.awt.Color;
    import java.awt.Label;
    import java.awt.Point;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.event.ActionEvent;
     
    /**
     * Simple property Window.
     * 
     * @author  JSoft
     */
     
    public class PropertiesWindow extends JFrame implements ChangeListener {
     
        JFrame propertiesWindow;
     
        JButton btn1;
        JButton btn2;
        JButton btn3;
        JButton btn4;
        JButton btn5;
        JButton setUp;
     
        JSlider widthSlider;
        JSlider heightSlider;
        JSlider pointXSlider;
        JSlider pointYSlider;
     
        JSlider redSchemeSlider;
        JSlider blueSchemeSlider;
        JSlider greenSchemeSlider;
     
        JLabel widthLabel;
        JLabel heightLabel;
        JLabel pointYLabel;
        JLabel pointXLabel;
     
        JLabel redSchemeLabel;
        JLabel blueSchemeLabel;
        JLabel greenSchemeLabel;
     
        JPanel windowPanel;
     
        // the spot where the sliders color combination will be displayed
        Label colorSpot;
     
        // the color spot label name
        Label spotLabel;
     
        // center point for the shape
        Point centerPoint;
     
        // dimension of the shape
        Dimension shapeDimension;
     
     
        // minimum value for the width of the shape
        private static final int WIDTH_MIN_VALUE = 100;
     
        // maximum value for width of the shape
        private static final int WIDTH_MAX_VALUE = 500;
     
        // minimum value for the height of the shape
        private static final int HEIGHT_MIN_VALUE = 100;
     
        // maximum value for the height of the shape
        private static final int HEIGHT_MAX_VALUE = 500;
     
        // minimum value for the center point (point x) of the shape
        private static final int MIN_POINT_X = 200;
     
        // maximum value for the center point (point x) of the shape
        private static final int MAX_POINT_X = 800;
     
        // minimum value for the center point (point y) of the shape
        private static final int MIN_POINT_Y = 100;
     
        // maximum value for the center point (point  y) of the shape
        private static final int MAX_POINT_Y = 500;
     
        // constant value for color scheme slider's minor tick
        private static final int COLOR_SLIDER_MINOR_TICK = 5;
     
        // constant value for color scheme slider's major tick
        private static final int COLOR_SLIDER_MAJOR_TICK = 10;
     
        // constant value of minor tick for the geometric pattern sliders
        private static final int MINOR_TICK = 10;
     
        // constant value of major tick for the geometric pattern sliders
        private static final int MAJOR_TICK = 100;
     
        public void showPropertyWindow() {
     
            propertiesWindow = new JFrame("Screensaver Properties Window");
     
            windowPanel = new JPanel();
            /**
             * this label will be the testing spot for the combination of colors
             * produced by color scheme sliders
             */
     
     
            widthSlider = new JSlider(WIDTH_MIN_VALUE, WIDTH_MAX_VALUE);
            heightSlider = new JSlider(HEIGHT_MIN_VALUE, HEIGHT_MAX_VALUE);
            pointXSlider = new JSlider(MIN_POINT_X, MAX_POINT_X);
            pointYSlider = new JSlider(MIN_POINT_Y, MAX_POINT_Y);
     
            // sliders for the adjustment of the color
            redSchemeSlider = new JSlider(SwingConstants.VERTICAL, 0 , 255, 0);
            blueSchemeSlider = new JSlider(SwingConstants.VERTICAL, 0, 255, 0);
            greenSchemeSlider = new JSlider(SwingConstants.VERTICAL, 0 ,255, 0);
     
            widthLabel = new JLabel();
            heightLabel = new JLabel();
            pointXLabel = new JLabel();
            pointYLabel = new JLabel();
     
            // Label for each color
            redSchemeLabel = new JLabel();
            blueSchemeLabel = new JLabel();
            greenSchemeLabel = new JLabel();
     
            // spot where the color that will be generated by the color sliders is displayed
            colorSpot = new Label();
     
            // Label for the width value slider
            widthLabel.setText("Width  :  ");
            widthLabel.setBounds(20, 10, 50, 40);
     
            // set the slider properties for the width
            widthSlider.setBounds(20, 35, 250, 50);
            widthSlider.setMinorTickSpacing(MINOR_TICK);
            widthSlider.setMajorTickSpacing(MAJOR_TICK);
            widthSlider.setPaintTicks(true);
            widthSlider.setPaintLabels(true);
            widthSlider.setToolTipText("Width");
            widthSlider.setForeground(Color.GRAY);
            widthSlider.addChangeListener(this);
     
            // Label for the height value slider
            heightLabel.setText("Height  :  ");
            heightLabel.setBounds(20, 90, 60, 70);
     
            // set the slider properties for the height
            heightSlider.setBounds(20, 135, 250, 45);
            heightSlider.setMinorTickSpacing(MINOR_TICK);
            heightSlider.setMajorTickSpacing(MAJOR_TICK);
            heightSlider.setPaintTicks(true);
            heightSlider.setPaintLabels(true);
            heightSlider.setToolTipText("Height");
            heightSlider.setForeground(Color.GRAY);
     
            // Label for the point x (center point)
            pointXLabel.setText("Point x  :  ");
            pointXLabel.setBounds(20, 175, 70, 100);
     
            // set the properties of the point x(center point) slider
            pointXSlider.setBounds(20, 230, 250, 50);
            pointXSlider.setMinorTickSpacing(MINOR_TICK);
            pointXSlider.setMajorTickSpacing(MAJOR_TICK);
            pointXSlider.setPaintTicks(true);
            pointXSlider.setPaintLabels(true);
            pointXSlider.setToolTipText("Center Point (x)");
            pointXSlider.setForeground(Color.GRAY);
     
            // Label for the point y (center point)
            pointYLabel.setText("Point y  :  ");
            pointYLabel.setBounds(20, 240, 70, 155);
     
            // set the properties of the point y(center point) slider
            pointYSlider.setBounds(20, 330, 250, 45);
            pointYSlider.setMinorTickSpacing(MINOR_TICK);
            pointYSlider.setMajorTickSpacing(MAJOR_TICK);
            pointYSlider.setPaintTicks(true);
            pointYSlider.setPaintLabels(true);
            pointYSlider.setToolTipText("Center Point (y)");
            pointYSlider.setForeground(Color.GRAY);
     
            // Label for each of the color scheme slider
            redSchemeLabel.setText("Red  :  ");
            redSchemeLabel.setBounds(300, 5, 50 , 50);
            greenSchemeLabel.setText("Green  :  ");
            greenSchemeLabel.setBounds(530, 5, 50, 50);
            blueSchemeLabel.setText("Blue  :  ");
            blueSchemeLabel.setBounds(420, 5, 50, 50);
     
            // set the properties of the red color scheme slider
            redSchemeSlider.setBounds(310, 40, 50, 280);
            redSchemeSlider.setMinorTickSpacing(COLOR_SLIDER_MINOR_TICK);
            redSchemeSlider.setMajorTickSpacing(COLOR_SLIDER_MAJOR_TICK);
            redSchemeSlider.setPaintTicks(true);
            redSchemeSlider.setPaintLabels(false);
            redSchemeSlider.setToolTipText("Red");
            redSchemeSlider.setForeground(Color.RED);
            redSchemeSlider.addChangeListener(this);
     
            // set the properties of the green color scheme slider
            greenSchemeSlider.setBounds(550, 40, 50, 280);
            greenSchemeSlider.setMinorTickSpacing(COLOR_SLIDER_MINOR_TICK);
            greenSchemeSlider.setMajorTickSpacing(COLOR_SLIDER_MAJOR_TICK);
            greenSchemeSlider.setPaintTicks(true);
            greenSchemeSlider.setPaintLabels(false);
            greenSchemeSlider.setToolTipText("Green");
            greenSchemeSlider.setForeground(Color.GREEN);
            greenSchemeSlider.addChangeListener(this);
     
            // set the properties of the blue color shceme slider
            blueSchemeSlider.setBounds(430, 40, 50, 280);
            blueSchemeSlider.setMinorTickSpacing(COLOR_SLIDER_MINOR_TICK);
            blueSchemeSlider.setMajorTickSpacing(COLOR_SLIDER_MAJOR_TICK);
            blueSchemeSlider.setPaintTicks(true);
            blueSchemeSlider.setPaintLabels(false);
            blueSchemeSlider.setToolTipText("Blue");
            blueSchemeSlider.setForeground(Color.blue);
            blueSchemeSlider.addChangeListener(this);
     
            // set the color spot in the panel
            colorSpot.setText("Shape's Color.");
            colorSpot.setFont(new Font("Monospaced",Font.CENTER_BASELINE ,20));
            colorSpot.setBounds(320, 350, 260, 40);
            colorSpot.setAlignment(Label.CENTER);
            colorSpot.setForeground(new Color(255, 255, 255));
            colorSpot.setBackground(new Color(0, 0, 0));
     
     
     
            Action properties = new AbstractAction() {
     
                public void actionPerformed(ActionEvent e) {
     
     
                }
            };
     
            // show the labels
            windowPanel.add(widthLabel);
     
            windowPanel.add(heightLabel);
     
            windowPanel.add(pointXLabel);
     
            windowPanel.add(pointYLabel);
     
            windowPanel.add(redSchemeLabel);
     
            windowPanel.add(blueSchemeLabel);
     
            windowPanel.add(greenSchemeLabel);
     
     
            // show the sliders
            windowPanel.add(widthSlider);
            windowPanel.add(heightSlider);
            windowPanel.add(pointXSlider);
            windowPanel.add(pointYSlider);
            windowPanel.add(redSchemeSlider);
            windowPanel.add(blueSchemeSlider);
            windowPanel.add(greenSchemeSlider);
            windowPanel.add(colorSpot);
     
            windowPanel.setLayout(null);
            windowPanel.setDoubleBuffered(false);
     
            propertiesWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            propertiesWindow.setSize(700, 450);
            propertiesWindow.setLocation(350, 200);
            propertiesWindow.setVisible(true);
            propertiesWindow.getContentPane().add(windowPanel);
        }
     
        public static void main(String[] args) {
     
            JSliderSample2 enhc = new JSliderSample2();
     
            enhc.showPropertyWindow();
        }
     
        public void stateChanged(ChangeEvent event) {
     
                int width = widthSlider.getValue();
                int height = heightSlider.getValue();
                int pointX = pointXSlider.getValue();
                int pointY = pointYSlider.getValue();
                int red = redSchemeSlider.getValue();
                int green = greenSchemeSlider.getValue();
                int blue = blueSchemeSlider.getValue();
     
                if ((red >= 200) && (red <= 255)) {
     
                    if ((green >= 200) && (green <= 255))  {
     
                        if ((blue >= 200) && (green <= 255)) {
     
                            colorSpot.setForeground(Color.BLACK);
                        }
                    }
                }
                else if ((red <= 50) && (red >= 0)) {
     
                    if ((green <= 50) && (green >= 0)) {
     
                        if ((blue <= 50) && (blue >= 0)) {
     
                            colorSpot.setForeground(Color.WHITE);
                        }
                    }
                }
     
                // set the spot color according to the colors generated by sliders
                colorSpot.setBackground(new Color(red, green, blue));
        }
    }


    why does this title - "Screensaver Properties Window" doesnt appear on the JFrame window?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: JFrame, frame's title doesnt appear.

    No idea why the title isn't showing, but you should make the call to add to the content pane prior to making the JFrame visible. Perhaps you can make another call to setTitle, but this shouldn't be necessary.

Similar Threads

  1. Overlapping windows? in a Jframe?
    By chronoz13 in forum AWT / Java Swing
    Replies: 6
    Last Post: November 21st, 2009, 12:01 PM
  2. how to make a simple JButton on a JFrame window?
    By chronoz13 in forum AWT / Java Swing
    Replies: 8
    Last Post: November 20th, 2009, 10:08 PM
  3. JFrame help
    By Uden in forum AWT / Java Swing
    Replies: 0
    Last Post: August 14th, 2009, 01:37 PM
  4. Change JFrame components problem
    By bruno88 in forum AWT / Java Swing
    Replies: 0
    Last Post: June 30th, 2009, 01:25 PM
  5. Replies: 3
    Last Post: February 26th, 2009, 05:21 PM