Hi friends,I got a problem down here..

Ok here's part of my First GUI code. all I want to do is locate the labelImage on the bottom half of the panel .. any idea..?
I tried the following steps.but it didn't help

Set the container's layout manager to null by calling setLayout(null).
Call the Component class's setbounds method for each of the container's children.
Call the Component class's repaint method.


thank you..


code

public void GUI4(){
    
    JFrame frame = new JFrame("GIS ");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    ImageIcon image = new ImageIcon("C:/icon.jpg");
    ImageIcon logo = new ImageIcon("C:/Earth.gif");

    JLabel label = new JLabel(image);
    JLabel labelImage = new JLabel(logo);


     built = new JButton("show built information");
     environment = new JButton("show environment information");
     road = new JButton("show Road network");
     traffic = new JButton("show Traffic Sensors");

     JPanel panel = new JPanel();

    panel.add(built);
    panel.add(environment);
    panel.add(road);
    panel.add(traffic);
    panel.add(labelImage);
    
   


    

    label.setPreferredSize(new Dimension(1200, 1000));
    Image img =new Image(image);
    JScrollPane jScrollPane = new JScrollPane(img);
    
    img.fechtData(roads1,roads2,envir,builtIn);

 

    frame.add(jScrollPane, BorderLayout.CENTER);
    //frame.setResizable(false);

    panel.setBackground(Color.cyan);
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    
  

    frame.getContentPane().add(BorderLayout.EAST,panel);
    frame.setSize(1500, 700);
   // frame.pack();
    frame.setVisible(true);


    }

Recommended Answers

All 4 Replies

Using a null layout manager is usually a mistake - layout managers are there for good reasons (different system font sizes on different machines, different screen resolutions, user-resizable windows...). This trick is to chose the simplest layout manager that does what you need. That usually means BorderLayout, FlowLayout, BoxLayout, or GridLayout. Remember a Panel can have a different layout manager from the frame that its in.
Here's a good place to start:
http://download.oracle.com/javase/tutorial/uiswing/layout/visual.html

If you're still stuck post a quick diagram showing what you want to achieve,

Using a null layout manager is usually a mistake - layout managers are there for good reasons (different system font sizes on different machines, different screen resolutions, user-resizable windows...). This trick is to chose the simplest layout manager that does what you need. That usually means BorderLayout, FlowLayout, BoxLayout, or GridLayout. Remember a Panel can have a different layout manager from the frame that its in.
Here's a good place to start:
http://download.oracle.com/javase/tutorial/uiswing/layout/visual.html

If you're still stuck post a quick diagram showing what you want to achieve,

I just want to bring that earth icon down.. thank you for the link..

Probably cleanest way is to put the buttons on their own new panel at the top of the existing panel, and the icon at the bottom of the existing panel. BorderLayout for the existing panel would be easy. Adding extra panels like this is a common method for organising windows. The alternative is to go to one of the top-end layout managers (eg GridBagLayout), but they have a steep learning curve.

Probably cleanest way is to put the buttons on their own new panel at the top of the existing panel, and the icon at the bottom of the existing panel. BorderLayout for the existing panel would be easy. Adding extra panels like this is a common method for organising windows. The alternative is to go to one of the top-end layout managers (eg GridBagLayout), but they have a steep learning curve.

Ok.I'm reading that article you suggested. thats really cool. I'll try your method.. thank you friend..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.