Full Component acces
Hello. I have successful made an layerPaned. But the JPanels stopped to repaint() when LayerPaned was added(worked before). Have have tried to fix this in lots of days now but I really cant solve it.
The only wrong I can think of is that I don't have full access to the layer. But have looked over http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Component.html many times and cant find anything useful. Can you see what I have missed? (I know it would be easyer if I made this "shorten problem example code" thing. But I have really tried do that for some hours, but the result was way to many lines. So just added main and layerPane classes where the problem should be located at):
import javax.swing.*;
import javax.swing.border.*;
import javax.accessibility.*;
import java.awt.*;
import java.awt.event.*;
publicclass LayeredPaneextends JPanel{
// Other classes added
private JLayeredPane layer;
private Performance p =new Performance(3);
// to reduce the code I removed this(stringView) JPanel(Just to not make you to confused)
private stringView sview =new stringView(p);
private View view =new View(p);
private TextField f =new TextField(view, p, sview);
// Constructor: taking in the layers to add
public LayeredPane(Performance p, stringView sview, View view, TextField f){
this.sview = sview;
this.view = view;
this.p = p;
this.f = f;
layer =new JLayeredPane();
layer.setPreferredSize(new Dimension(600,500));
// creating the panels with the createPane1(2) methods
View pane1 = createPane1(new Point(0, 0));
TextField pane2 = createPane2(new Point(50, 50));
// adding the panels and z possition for them
layer.add(pane1,new Integer(1));
layer.add(pane2,new Integer(2));
add(layer);
}
// In this methods I have tried to add things like this without any result:
/**
v.setEnabled(true);
v.enable(true);
v.setFocusable(true);
*/
private View createPane1(Point origin){
View v =new View(p);
v.setOpaque(true);
v.setBounds(0, 0, 600, 500);
return v;
}
private TextField createPane2(Point origin){
TextField f =new TextField(view, p, sview);
f.setOpaque(true);
f.setBounds(200, 400, 300, 50);
f.requestFocus();
return f;
}
}
And here is the Main class I also had to change to add the JComponent/layers
import javax.swing.*;
import javax.swing.border.*;
import javax.accessibility.*;
import java.awt.*;
import java.awt.event.*;
publicclass Main{
publicstaticvoid main(String[] args){
//Create and set up the window.
JFrame frame =new JFrame("title");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane with all the classes
Performance p =new Performance(3);
// stringView and View draws up correctly here but NEVER repaints(have told it to repaint in another class)
stringView s =new stringView(p);
View v =new View(p);
TextField f =new TextField(v, p, s);
v.setBounds(0,0,500,500);
JComponent newContentPane =new LayeredPane(p, s, v, f);
// Here comes some desperate tries. . . .
newContentPane.setEnabled(true);
newContentPane.enable(true);
newContentPane.setFocusable(true);
newContentPane.setOpaque(true);
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
}
}
Offcorse it repaints as a JFrame do when I rezise the JFrame window with the mouse when the program is running. Thats why I also came up with the question: is it not possible to somehow make the framewindow change width/height with 1 px or something by a method call?
Great thanks in advance!!

