first JLayeredPane

Hello. I磎 trying to do my first JLayeredPane but as always it dosent work the first time. Right now I磎 getting the error:

"cannot find symbol - method setLayer(View,java.lang.integer,java.awt.point)"

setLayer :: (Component c, int layer, int position)

my code:

setLayer(view, new Integer(1),0);

I guess it磗 my "position"(0) who is wrong. But how should the last arguemnt "position" be set?

Message was edited by:

Hunter78 (rephrasing question)

[492 byte] By [Hunter78a] at [2007-11-27 6:54:53]
# 1

I try to post the full code:

import java.awt.*;

import javax.swing.*;

//View class

public class Main{

public static void main(String[] args){

JFrame f = new JFrame("title");

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setSize(600, 500);

// creating 2 view classes/JPanels

View viewPanel1 panel1 = new viewPanel1();

View viewPanel2 panel2 = new viewPanel2();

// creating the layerPanel and adding the JPanels

JLayeredPane lp = new JLayeredPane();

lp.add(view);

lp.add(sview);

// the possition for the specified Panel

setLayer(view, new Integer(1),1);

setLayer(sview, new Integer(1),-1);

f.add(lp);

f.setVisible(true);

}

}

Hunter78a at 2007-7-12 18:30:08 > top of Java-index,Desktop,Core GUI APIs...
# 2

The posted code is not compileable.

If you really need help then you need to create a

[url=http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example

Program[/url] (SSCCE) that demonstrates the incorrect behaviour.

Don't forget to use the [url=http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url]

so the posted code retains its original formatting.

regards

Aniruddha

Aniruddha-Herea at 2007-7-12 18:30:08 > top of Java-index,Desktop,Core GUI APIs...
# 3

Thanks for reply. I磎 not very good at java and becouse of that I磎 not very good at SSCCE but I have done my best. Hope this will make it easier:

First JPanel Class:

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class View extends JPanel{

public View(){

setPreferredSize(new Dimension(200,200));

}

public void paintComponent(Graphics g){

g.drawString("TEST",10,10);

}

}

Second JPanel class:

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class stringView extends JPanel{

public stringView(){

setPreferredSize(new Dimension(100,100));

}

public void paintComponent(Graphics g){

g.drawString("TEST2",10,10);

}

}

Main class who gets the error:

"Cannot find symbol - method setLayer(View,java.lang.Integer,int)"

import java.awt.*;

import javax.swing.*;

public class Main{

public static void main(String[] args){

JFrame f = new JFrame("title");

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setSize(600, 500);

// creating 2 view classes/JPanels

View panel1 = new View();

stringView panel2 = new stringView();

// creating the layerPanel and adding the JPanels

JLayeredPane lp = new JLayeredPane();

lp.add(panel1);

lp.add(panel2);

// the possition for the specified Panel

setLayer(panel1, new Integer(1),1);

setLayer(panel2, new Integer(2),-1);

f.add(lp);

f.setVisible(true);

}

}

Hunter78a at 2007-7-12 18:30:08 > top of Java-index,Desktop,Core GUI APIs...
# 4

hi

where do you think this part is?

// the possition for the specified Panel

setLayer(panel1, new Integer(1),1);

setLayer(panel2, new Integer(2),-1);

check i9t? where setLayer ?

Aniruddha-Herea at 2007-7-12 18:30:08 > top of Java-index,Desktop,Core GUI APIs...
# 5

ah. offcorse it should be

lp.setLayer(panel1, new Integer(1),1);

lp.setLayer(panel2, new Integer(2),-1);

thanks. But now nothing is showing up when running the program. Should not the "drawStrings" from the JPanels be shown? What have I missed?

Hunter78a at 2007-7-12 18:30:08 > top of Java-index,Desktop,Core GUI APIs...
# 6
Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/layeredpane.html]How to Use Layered Panes[/url] for a working example.
camickra at 2007-7-12 18:30:08 > top of Java-index,Desktop,Core GUI APIs...
# 7

I just added an LayeredPane class to my program after many hours reading the tutorial. But once I succeded my "View" classes did no longer listen to my calls to repaint().

It draws everything up just fine when starting the program but dose never repaint even if I say it should repaint() in every method. Any idea what could be wrong?

Hunter78a at 2007-7-12 18:30:08 > top of Java-index,Desktop,Core GUI APIs...