JLayeredPane help
I need to create a GUI with a JPanel showing a plot, and on the bottom left corner I'd like to have a JTable showing some data. The LayeredPane would be real nice to do that. I tried but the objects in the LayeredPane did not resize with the window. So, my question is: is there any way to fix the objects in the LayeredPane so they resize with the window much like if it was a BorderLayout or so?
Here is a little test I did without the plot; but it exemplifies real well what I mean:
public class TestLayersMain extends javax.swing.JFrame {
/** Creates new form TestLayersMain */
public TestLayersMain() {
initComponents();
private void initComponents() {
jPanel2 = new javax.swing.JPanel();
jLayeredPane2 = new javax.swing.JLayeredPane();
jScrollPane3 = new javax.swing.JScrollPane();
jTextArea2 = new javax.swing.JTextArea();
jScrollPane4 = new javax.swing.JScrollPane();
jTable2 = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel2.setLayout(new java.awt.BorderLayout());
jScrollPane3.setViewportView(jTextArea2);
jScrollPane3.setBounds(10, 10, 430, 280);
jLayeredPane2.add(jScrollPane3, javax.swing.JLayeredPane.DEFAULT_LAYER);
jTable2.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
jScrollPane4.setViewportView(jTable2);
jScrollPane4.setBounds(10, 190, 200, 100);
jLayeredPane2.add(jScrollPane4, javax.swing.JLayeredPane.POPUP_LAYER);
jPanel2.add(jLayeredPane2, java.awt.BorderLayout.CENTER);
getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
pack();
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TestLayersMain().setVisible(true);
private javax.swing.JLayeredPane jLayeredPane2;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JTable jTable2;
private javax.swing.JTextArea jTextArea2;
// End of variables declaration
}Thanks in advance!
[url http://java.sun.com/docs/books/tutorial/uiswing/events/componentlistener.html]How to Write a Component Listener
Try adding a ComponentListener to the LayeredPane and handle componentResized() method and then resize your components manually.
Similar Messages
-
JLayeredPane inside JScrollPane - please help!!
Hi everyone!
i'm having the following problem: I need to add a JLayeredPane to a JScrollPane. this JLayeredPane contains a JGraph and this is what I'm doing:
jlayeredPane = new JLayeredPane();
jlayeredPane.add(graph, JLayeredPane.DEFAULT_LAYER);
jlayeredPane.setPreferredSize(new Dimension(1000,1000));
jlayeredPane.setMinimumSize(new Dimension(1000,1000));
jsp = new JScrollPane(jlayeredPane);
add(jsp);
[/code
but the graph doesn't show up at all. can anyone help me please. i have a deadline today and really need to figure this out. thanx a lothere's some of my code:
inside the construtor of a panel
graph = new Graph(new DefaultGraphModel(), new GraphLayoutCache());
// JLayeredPane
jlayeredPane = new JLayeredPane();
// jlayeredPane.setMinimumSize(new Dimension(400,400));
jlayeredPane.setPreferredSize(new Dimension(400, 400));
jlayeredPane.add(graph, JLayeredPane.DEFAULT_LAYER);
jsp= new JScrollPane(jlayeredPane);
jsp.addComponentListener(this);
add(jsp, BorderLayout.CENTER);
public void componentResized(ComponentEvent e) {
int layeredPaneWidth = jlayeredPane.getWidth();
int layeredPaneHeight = jlayeredPane.getHeight();
int viewportwidth = jspLayered.getViewport().getWidth();
int viewportheight = jspLayered.getViewport().getHeight();
int width = Math.max(layeredPaneWidth, viewportwidth);
int height = Math.max(layeredPaneHeight, viewportheight);
jspLayered.getViewport().setSize(new Dimension(width, height));
graph.setSize(width, height);
graph.setPreferredSize(new Dimension(width, height));
} -
basically I need to create a panel with a background, then use JLayeredPane to put 2 other panel on top of each other over the background. The problem is that each panel will display properly by with the background but not all 3 together.
/* main gui class for the four score game.*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GuiMain extends JFrame
//declare variables
private JButton quit = new JButton("Quit");
private JButton restart = new JButton("Restart");
//panels
private BoardPanel myBoard = new BoardPanel();
private JPanel South = new JPanel();
//embedded main class used for testing
public static void main(String[] args)
new GuiMain();
/*no arg constructor which zeroes the bead array, creates a new window using the boxlayout manager,
* creates the board, and adds the quit/restart buttons
public GuiMain()
super("Four Score");
this.addComponentListener(new ResizeListener());
setSize(640,480);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
myBoard.setBorder(BorderFactory.createLineBorder(Color.black));
restart.addActionListener(new ResetListener());
quit.addActionListener(new QuitListener());
South.add(quit);
South.add(restart);
South.setBorder(BorderFactory.createLineBorder(Color.green));
add(myBoard, BorderLayout.CENTER);
add(South, BorderLayout.SOUTH);
repaint();
setVisible(true);
//sends a new complete set of beads to the board
public void updateBoard(int[][][] newBeads)
myBoard.updateBoard(newBeads);
//updates a specific bead then calls the updateboard method
public void updateBead(int x, int y,int z, int color)
myBoard.updateBead(x, y, z, color);
//checks if a peg at a set of coordinates is full
public boolean isFull(int x, int y)
return myBoard.isFull(x,y);
/* customer action listener for the reset button
* resets the beads array to all zeroes (empty) and
* sends the command "reset;" to the player
private class ResetListener implements ActionListener
public void actionPerformed(ActionEvent e)
int[][][] beads = new int[4][4][4];
for(int i = 0; i < 4; i++)
for(int j = 0; j<4; j++)
for(int k=0; k<4;k++)
beads[i][j][k] = 0;
updateBoard(beads);
sendCommand("reset;");
/* customer action listener for the quit button
* sends a "quit;" command to the player.
public class QuitListener implements ActionListener
public void actionPerformed(ActionEvent e)
sendCommand("Quit;");
System.exit(0); //REMOVE AFTER TESTING
public void sendCommand(String command)
//so far unused as I still need to work out sending the commands to the appropriate place
public class ResizeListener implements ComponentListener
public void componentResized(ComponentEvent e)
if(getWidth() != 640 || getHeight() != 480)
setSize(640,480);
public void componentMoved(ComponentEvent e){}
public void componentShown(ComponentEvent e) {}
public void componentHidden(ComponentEvent e) {}
/* class which creates the actual game board
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class BoardPanel extends JPanel
enum BeadStatus {EMPTY, WHITE, BLACK};
//variables, basic x and y starting points for drawing the board.
final int x = 100;
final int y = 100;
final int[] boardxPoints = {x,x+320,x+420,x+100};
final int[] boardyPoints = {y,y,y+200,y+200};
//array for the beads
private int[][][] beads = new int[4][4][4];
private PegButton[] pegs = new PegButton[16];
public JPanel pegsPanel = new JPanel();
public BeadLayer beadsPanel = new BeadLayer();
JLayeredPane layers = new JLayeredPane();
* no arg constructor which simply zeroes the bead array
public BoardPanel()
pegsPanel.setLocation(0,0);
pegsPanel.setPreferredSize(new Dimension(630,480));
pegsPanel.setOpaque(false);
setOpaque(false);
drawPegs();
layers.setBorder(BorderFactory.createTitledBorder(
"Test"));
layers.add(pegsPanel, 1);
beadsPanel.setLocation(0,0);
beadsPanel.setPreferredSize(new Dimension(630,480));
//layers.add(beadsPanel, new Integer(1));
add(layers);
* overriden paint component method which draws out the board, pegs, and beads
public void paintComponent(Graphics g)
super.paintComponent(g);
g.setColor(Color.blue); //board background color
g.fillPolygon(boardxPoints,boardyPoints, 4); //create the basic board shape
drawGrid(g);
* method to draw out the grid shape
public void drawGrid(Graphics g)
int p;
int q;
g.setColor(Color.cyan);
//draw the vertical lines
for(int i=0; i<5;i++)
p=x+(i*80);
g.drawLine(p,y,p+100,y+200);
//draw the horizontal lines
for (int j=0; j<4; j++)
p=x+(j*25);
q=y+(50*j);
g.drawLine(p,q,p+320,q);
g.drawLine(x+100,y+200,x+420,y+200);
* draw out the 16 pegs in proper position
public void drawPegs()
int p = x;
int q = y;
int n;
for(int i=0; i<4;i++)
for(int j=0; j < 4; j++)
p = x+(j*80+40)+(i*25+12)-5;
q = y+(i*50+25)-80;
//g.fillRect(p,q,10,75);
//g.fillArc(p, q-5, 10, 10, 0, 180);
n =j+(i*4);
pegs[n] = new PegButton(i,j);
pegs[n].setLocation(p,q);
pegsPanel.add(pegs[n]);
//updates the board by reading in a new bead array then repainting
public void updateBoard(int[][][] beads)
for(int i = 0; i < 4; i++)
for(int j = 0; j<4; j++)
for(int k=0; k<4; k++)
this.beads[i][j][k] = beads[i][j][k];
repaint(); //inheirited method which causes paintcomponent to be called again
public void updateBead(int x, int y, int z, int color)
beads[x][y][z] = color;
repaint();
//returns true if a peg is full
public boolean isFull(int x, int y)
if (beads[x][y][3] != 0)
return false;
return true;
import java.awt.*;
import javax.swing.*;
public class BeadLayer extends JPanel
enum BeadStatus {EMPTY, WHITE, BLACK};
final int x = 100;
final int y = 100;
private int[][][] beads = new int[4][4][4];
public BeadLayer()
for(int i = 0; i < 4; i++)
for(int j = 0; j<4; j++)
for(int k=0; k<4; k++)
beads[i][j][k] = 1;
repaint();
//method which takes in a set of coordinates and a color then draws the bead at the correct position
public void paintComponent(Graphics g)
//reads through the bead array and calls the drawbead method where required
for(int i = 0; i<4; i++)
for(int j = 0; j<4; j++)
for(int k=0; k<4;k++)
if(beads[i][j][k] == 1)
drawBead(i,j,k,BeadStatus.BLACK,g);
else if(beads[i][j][k] == 2)
drawBead(i,j,k,BeadStatus.WHITE,g);
public void drawBead(int x, int y, int z, BeadStatus color, Graphics g)
x = this.x+(x*80+40)+(y*25+12)-10;
y = this.y+(y*50+25)-18-(18*z);
if(color == BeadStatus.WHITE)
g.setColor(Color.WHITE);
else
g.setColor(Color.BLACK);
g.fillOval(x, y, 20, 18);
g.setColor(Color.GREEN);
g.drawOval(x, y, 20, 18);
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class PegButton extends JButton implements ActionListener
private String coord;
public PegButton(int x, int y)
getCoord(x,y);
this.setPreferredSize(new Dimension(10,75));
this.setBorderPainted(false);
addActionListener(this);
public void getCoord(int x, int y)
y+=1;
switch(x)
case 0: coord = "A"+Integer.toString(y)+".";
break;
case 1: coord = "B"+Integer.toString(y)+".";
break;
case 2: coord = "C"+Integer.toString(y)+".";
break;
case 3: coord = "D"+Integer.toString(y)+".";
break;
public void setLocation(int x,int y)
if (y != 5)
super.setLocation(x,y);
public void paintComponent(Graphics g)
g.setColor(Color.RED);
g.fillRect(0, 7, 10, 75);
g.fillArc(0, 0, 10, 15, 0, 180);
public void actionPerformed(ActionEvent e)
System.out.println(coord);
}Multi-post: http://forum.java.sun.com/thread.jspa?threadID=5274611
-
Chess game variant - help using JLayeredPane and the drag layer.
Hi there!
I'm making a game based on chess, but with slightly different rules. The code at the bottom of this thread...
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=518707
... forms the basis of the game board, and this is how I have implemented the dragging and dropping of pieces. My game, however is slightly different as there is a single neutral piece (the ball), which players can manipulate by moving one of their pieces to the square containing the ball, then moving the ball to another location.
When a player clicks and drags a piece to the ball square, then releases, I want to attach the 'ball' JLabel to the mouse so that the player can move it around the board WITHOUT holding down the mouse button. Then, when the player clicks again the ball is moved to the new square.
The only problem I have is attaching the 'ball' to the mouse so I can move it around (without the user having to hold the mouse button down). I thought about tried using the drag layer, but I couldn't quite get that working. I also thought about using the mouseMoved(MouseEvent e) and mouseClicked(MouseEvent e) methods.
I'm pretty new to this coding stuff, so any suggestions would be great.
Thanks!Using the drag layer isn't going to work unless you are using an honest to goodness component for the ball. Your other option might be to try to use the glasspane, which is a pain in the neck, or a floating window component.
In any case,I built the code below for dragging Windows around in a frame. You're free to use it but please site me in your school or business work
package tjacobs.ui;
import java.awt.*;
import java.awt.event.*;
public abstract class WindowUtilities {
public static Point getBottomRightOfScreen(Component c) {
Dimension scr_size = Toolkit.getDefaultToolkit().getScreenSize();
Dimension c_size = c.getSize();
return new Point(scr_size.width - c_size.width, scr_size.height - c_size.height);
public static class Draggable extends MouseAdapter implements MouseMotionListener {
Point mLastPoint;
Window mWindow;
public Draggable(Window w) {
w.addMouseMotionListener(this);
w.addMouseListener(this);
mWindow = w;
public void mousePressed(MouseEvent me) {
mLastPoint = me.getPoint();
public void mouseReleased(MouseEvent me) {
mLastPoint = null;
public void mouseMoved(MouseEvent me) {}
public void mouseDragged(MouseEvent me) {
int x, y;
if (mLastPoint != null) {
x = mWindow.getX() + (me.getX() - (int)mLastPoint.getX());
y = mWindow.getY() + (me.getY() - (int)mLastPoint.getY());
mWindow.setLocation(x, y);
} -
Netbeans 5.0 crashes... please help..
Hi, i just installed netbeans 5.0 with the latest java package. When i first execute the program, it crashes. Below is the error log. Can anyone help me? This is not the first time. I already uninstall and reinstall java and reinstalling netbeans. This same outcome.
# An unexpected error has been detected by HotSpot Virtual Machine:
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00d18280, pid=3352, tid=3872
# Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode, sharing)
# Problematic frame:
# J java.awt.GradientPaintContext.clipFillRaster([IIIIIDDD)V
--------------- T H R E A D ---------------
Current thread (0x030081e0): JavaThread "AWT-EventQueue-1" [_thread_in_Java, id=3872]
siginfo: ExceptionCode=0xc0000005, reading address 0xffffffff
Registers:
EAX=0x1cadd928, EBX=0x00000000, ECX=0x1cb53c80, EDX=0x00000000
ESP=0x0365e4f8, EBP=0x0365e528, ESI=0x00000000, EDI=0x00000020
EIP=0x00d18280, EFLAGS=0x00010246
Top of Stack: (sp=0x0365e4f8)
0x0365e4f8: 00000000 00000000 00000000 00000000
0x0365e508: 00ad29fa 00000001 1cadd934 00000000
0x0365e518: 00000000 ffffffff 1c71c71c 3fbc71c7
0x0365e528: 0365e588 00d8e3eb 1c71c71c 3fac71c7
0x0365e538: 00000000 00000000 1c71c71c 3fbc71c7
0x0365e548: 00000000 00000020 00000000 00000000
0x0365e558: 1cadd928 1cb53c80 0365e5ac 00000000
0x0365e568: 00000000 1cadd928 00000000 00000000
Instructions: (pc=0x00d18280)
0x00d18270: dd 45 18 dd 5d f8 8b 7d 24 dd 45 f8 d9 ee d9 c9
0x00d18280: df e9 dd c0 d9 f7 0f 8a 06 00 00 00 0f 86 0e 00
Stack: [0x03620000,0x03660000), sp=0x0365e4f8, free space=249k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
J java.awt.GradientPaintContext.clipFillRaster([IIIIIDDD)V
J java.awt.GradientPaintContext.getRaster(IIII)Ljava/awt/image/Raster;
J sun.java2d.pipe.AlphaPaintPipe.renderPathTile(Ljava/lang/Object;[BIIIIII)V
j sun.java2d.pipe.SpanShapeRenderer$Composite.renderBox(Ljava/lang/Object;IIII)V+15
j sun.java2d.pipe.SpanShapeRenderer.spanClipLoop(Ljava/lang/Object;Lsun/java2d/pipe/SpanIterator;Lsun/java2d/pipe/Region;[I)V+56
j sun.java2d.pipe.SpanShapeRenderer.renderSpans(Lsun/java2d/SunGraphics2D;Lsun/java2d/pipe/Region;Ljava/awt/Shape;Lsun/java2d/pipe/ShapeSpanIterator;)V+131
j sun.java2d.pipe.SpanShapeRenderer.renderPath(Lsun/java2d/SunGraphics2D;Ljava/awt/Shape;)V+43
j sun.java2d.pipe.SpanShapeRenderer.fill(Lsun/java2d/SunGraphics2D;Ljava/awt/Shape;)V+33
j sun.java2d.pipe.PixelToShapeConverter.fillPolygon(Lsun/java2d/SunGraphics2D;[I[II)V+14
j sun.java2d.pipe.ValidatePipe.fillPolygon(Lsun/java2d/SunGraphics2D;[I[II)V+17
j sun.java2d.SunGraphics2D.fillPolygon([I[II)V+8
j java.awt.Graphics.fillPolygon(Ljava/awt/Polygon;)V+13
j org.netbeans.swing.tabcontrol.plaf.WinXPEditorTabCellRenderer.paintGradient(Ljava/awt/Graphics;Lorg/netbeans/swing/tabcontrol/plaf/WinXPEditorTabCellRenderer;Lorg/netbeans/swing/tabcontrol/plaf/TabPainter;)V+39
j org.netbeans.swing.tabcontrol.plaf.WinXPEditorTabCellRenderer.access$700(Ljava/awt/Graphics;Lorg/netbeans/swing/tabcontrol/plaf/WinXPEditorTabCellRenderer;Lorg/netbeans/swing/tabcontrol/plaf/TabPainter;)V+3
j org.netbeans.swing.tabcontrol.plaf.WinXPEditorTabCellRenderer$WinXPPainter.paintInterior(Ljava/awt/Graphics;Ljava/awt/Component;)V+8
j org.netbeans.swing.tabcontrol.plaf.AbstractTabCellRenderer.paintComponent(Ljava/awt/Graphics;)V+27
j javax.swing.JComponent.paint(Ljava/awt/Graphics;)V+260
j org.netbeans.swing.tabcontrol.plaf.BasicTabDisplayerUI.paint(Ljava/awt/Graphics;Ljavax/swing/JComponent;)V+404
j javax.swing.plaf.ComponentUI.update(Ljava/awt/Graphics;Ljavax/swing/JComponent;)V+32
j javax.swing.JComponent.paintComponent(Ljava/awt/Graphics;)V+26
j javax.swing.JComponent.paint(Ljava/awt/Graphics;)V+260
J javax.swing.JComponent.paintChildren(Ljava/awt/Graphics;)V
v ~RuntimeStub::alignment_frame_return Runtime1 stub
j javax.swing.JComponent.paint(Ljava/awt/Graphics;)V+292
J javax.swing.JComponent.paintChildren(Ljava/awt/Graphics;)V
v ~RuntimeStub::alignment_frame_return Runtime1 stub
j javax.swing.JComponent.paint(Ljava/awt/Graphics;)V+292
J javax.swing.JComponent.paintChildren(Ljava/awt/Graphics;)V
v ~RuntimeStub::alignment_frame_return Runtime1 stub
j javax.swing.JComponent.paint(Ljava/awt/Graphics;)V+292
J javax.swing.JComponent.paintChildren(Ljava/awt/Graphics;)V
j javax.swing.JComponent.paint(Ljava/awt/Graphics;)V+292
j org.netbeans.core.windows.view.ui.MultiSplitPane.paint(Ljava/awt/Graphics;)V+2
J javax.swing.JComponent.paintChildren(Ljava/awt/Graphics;)V
v ~RuntimeStub::alignment_frame_return Runtime1 stub
j javax.swing.JComponent.paint(Ljava/awt/Graphics;)V+292
J javax.swing.JComponent.paintChildren(Ljava/awt/Graphics;)V
j javax.swing.JComponent.paint(Ljava/awt/Graphics;)V+292
j javax.swing.JLayeredPane.paint(Ljava/awt/Graphics;)V+73
J javax.swing.JComponent.paintChildren(Ljava/awt/Graphics;)V
v ~RuntimeStub::alignment_frame_return Runtime1 stub
j javax.swing.JComponent.paint(Ljava/awt/Graphics;)V+292
J javax.swing.JComponent.paintChildren(Ljava/awt/Graphics;)V
v ~RuntimeStub::alignment_frame_return Runtime1 stub
j javax.swing.JComponent.paint(Ljava/awt/Graphics;)V+292
J javax.swing.JComponent.paintChildren(Ljava/awt/Graphics;)V
j javax.swing.JComponent.paint(Ljava/awt/Graphics;)V+292
j javax.swing.JLayeredPane.paint(Ljava/awt/Graphics;)V+73
J javax.swing.JComponent.paintChildren(Ljava/awt/Graphics;)V
j javax.swing.JComponent.paint(Ljava/awt/Graphics;)V+292
j javax.swing.JComponent.paintWithOffscreenBuffer(Ljavax/swing/JComponent;Ljava/awt/Graphics;IIIILjava/awt/Image;)V+174
j javax.swing.JComponent.paintDoubleBuffered(Ljavax/swing/JComponent;Ljava/awt/Component;Ljava/awt/Graphics;IIII)Z+131
J javax.swing.JComponent._paintImmediately(IIII)V
j javax.swing.JComponent.paintImmediately(IIII)V+83
j javax.swing.RepaintManager.paintDirtyRegions()V+314
j javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run()V+32
j java.awt.event.InvocationEvent.dispatch()V+47
j java.awt.EventQueue.dispatchEvent(Ljava/awt/AWTEvent;)V+26
J java.awt.EventDispatchThread.pumpOneEventForHierarchy(ILjava/awt/Component;)Z
v ~RuntimeStub::alignment_frame_return Runtime1 stub
j java.awt.EventDispatchThread.pumpEventsForHierarchy(ILjava/awt/Conditional;Ljava/awt/Component;)V+26
j java.awt.EventDispatchThread.pumpEvents(ILjava/awt/Conditional;)V+4
j java.awt.EventDispatchThread.pumpEvents(Ljava/awt/Conditional;)V+3
j java.awt.EventDispatchThread.run()V+9
v ~StubRoutines::call_stub
V [jvm.dll+0x845a9]
V [jvm.dll+0xd9317]
V [jvm.dll+0x8447a]
V [jvm.dll+0x841d7]
V [jvm.dll+0x9ed69]
V [jvm.dll+0x109fe3]
V [jvm.dll+0x109fb1]
C [MSVCRT.dll+0x2a3b0]
C [kernel32.dll+0xb50b]
--------------- P R O C E S S ---------------
Java Threads: ( => current thread )
0x02d1d188 JavaThread "Image Fetcher 1" daemon [_thread_blocked, id=216]
0x02d00d90 JavaThread "Image Fetcher 0" daemon [_thread_blocked, id=3472]
0x0302df18 JavaThread "Inactive RequestProcessor thread [Was:Parsing Event Queue/org.netbeans.modules.javacore.JMManager$5]" daemon [_thread_blocked, id=3532]
0x032ac270 JavaThread "Inactive RequestProcessor thread [Was:Default RequestProcessor/org.netbeans.modules.editor.errorstripe.AnnotationView$RepaintTask]" daemon [_thread_blocked, id=2444]
0x032d7dd0 JavaThread "Inactive RequestProcessor thread [Was:Default RequestProcessor/org.netbeans.modules.navigator.NavigatorController$ActNodeSetter]" daemon [_thread_blocked, id=2364]
0x02f42500 JavaThread "Inactive RequestProcessor thread [Was:ToolTip-Evaluator/org.netbeans.modules.editor.NbToolTip$Request]" daemon [_thread_blocked, id=1060]
0x02ced900 JavaThread "Inactive RequestProcessor thread [Was:Overriddens Queue/org.netbeans.modules.java.OverrideAnnotationSupport$Request]" daemon [_thread_blocked, id=3868]
0x02e1d7d0 JavaThread "MDR event dispatcher" daemon [_thread_blocked, id=3996]
0x00037b60 JavaThread "DestroyJavaVM" [_thread_blocked, id=900]
=>0x030081e0 JavaThread "AWT-EventQueue-1" [_thread_in_Java, id=3872]
0x031ebb28 JavaThread "TimerQueue" daemon [_thread_blocked, id=2448]
0x031d2b80 JavaThread "Inactive RequestProcessor thread [Was:ListModelSupport loader/org.netbeans.modules.java.navigation.spi.ListModelSupport$Loader]" daemon [_thread_blocked, id=1836]
0x031a6dd8 JavaThread "Inactive RequestProcessor thread [Was:Java Node State Updater/org.netbeans.modules.java.JavaNode$StateUpdater]" daemon [_thread_blocked, id=1788]
0x0316cb90 JavaThread "Inactive RequestProcessor thread [Was:ToolTip-Evaluator/org.netbeans.modules.editor.NbToolTip$Request]" daemon [_thread_blocked, id=3228]
0x02f3d390 JavaThread "Java2D Disposer" daemon [_thread_blocked, id=3456]
0x00acf638 JavaThread "AWT-Windows" daemon [_thread_in_native, id=628]
0x02ecd948 JavaThread "AWT-Shutdown" [_thread_blocked, id=2720]
0x00acd950 JavaThread "Timer-0" daemon [_thread_blocked, id=1852]
0x02cd8820 JavaThread "CLI Requests Server" daemon [_thread_in_native, id=1340]
0x00ab7a70 JavaThread "Active Reference Queue Daemon" daemon [_thread_blocked, id=2492]
0x00a70268 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=3004]
0x00a6eed8 JavaThread "CompilerThread0" daemon [_thread_blocked, id=3440]
0x00a6e1c0 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=3444]
0x0003fa20 JavaThread "Finalizer" daemon [_thread_blocked, id=3492]
0x00a48aa0 JavaThread "Reference Handler" daemon [_thread_blocked, id=2580]
Other Threads:
0x00a68428 VMThread [id=3628]
0x00a714b8 WatcherThread [id=3752]
VM state:not at safepoint (normal execution)
VM Mutex/Monitor currently owned by a thread: None
Heap
def new generation total 2304K, used 914K [0x1ca70000, 0x1ccf0000, 0x1d440000)
eden space 2048K, 44% used [0x1ca70000, 0x1cb54868, 0x1cc70000)
from space 256K, 0% used [0x1cc70000, 0x1cc70000, 0x1ccb0000)
to space 256K, 0% used [0x1ccb0000, 0x1ccb0000, 0x1ccf0000)
tenured generation total 30272K, used 16957K [0x1d440000, 0x1f1d0000, 0x24a70000)
the space 30272K, 56% used [0x1d440000, 0x1e4cf758, 0x1e4cf800, 0x1f1d0000)
compacting perm gen total 32768K, used 21094K [0x24a70000, 0x26a70000, 0x2aa70000)
the space 32768K, 64% used [0x24a70000, 0x25f098f0, 0x25f09a00, 0x26a70000)
ro space 8192K, 66% used [0x2aa70000, 0x2afcbcc0, 0x2afcbe00, 0x2b270000)
rw space 12288K, 46% used [0x2b270000, 0x2b812060, 0x2b812200, 0x2be70000)
Dynamic libraries:
0x00400000 - 0x0040c000 C:\Program Files\Java\jdk1.5.0_06\jre\bin\java.exe
0x7c900000 - 0x7c9b0000 C:\WINDOWS\system32\ntdll.dll
0x7c800000 - 0x7c8f4000 C:\WINDOWS\system32\kernel32.dll
0x77dd0000 - 0x77e6b000 C:\WINDOWS\system32\ADVAPI32.dll
0x77e70000 - 0x77f01000 C:\WINDOWS\system32\RPCRT4.dll
0x77c10000 - 0x77c68000 C:\WINDOWS\system32\MSVCRT.dll
0x6d6e0000 - 0x6d874000 C:\Program Files\Java\jdk1.5.0_06\jre\bin\client\jvm.dll
0x77d40000 - 0x77dd0000 C:\WINDOWS\system32\USER32.dll
0x77f10000 - 0x77f56000 C:\WINDOWS\system32\GDI32.dll
0x76b40000 - 0x76b6d000 C:\WINDOWS\system32\WINMM.dll
0x6d2f0000 - 0x6d2f8000 C:\Program Files\Java\jdk1.5.0_06\jre\bin\hpi.dll
0x76bf0000 - 0x76bfb000 C:\WINDOWS\system32\PSAPI.DLL
0x6d6b0000 - 0x6d6bc000 C:\Program Files\Java\jdk1.5.0_06\jre\bin\verify.dll
0x6d370000 - 0x6d38d000 C:\Program Files\Java\jdk1.5.0_06\jre\bin\java.dll
0x6d6d0000 - 0x6d6df000 C:\Program Files\Java\jdk1.5.0_06\jre\bin\zip.dll
0x6d530000 - 0x6d543000 C:\Program Files\Java\jdk1.5.0_06\jre\bin\net.dll
0x71ab0000 - 0x71ac7000 C:\WINDOWS\system32\WS2_32.dll
0x71aa0000 - 0x71aa8000 C:\WINDOWS\system32\WS2HELP.dll
0x76d60000 - 0x76d79000 C:\WINDOWS\system32\iphlpapi.dll
0x76d40000 - 0x76d58000 C:\WINDOWS\system32\MPRAPI.dll
0x77cc0000 - 0x77cf2000 C:\WINDOWS\system32\ACTIVEDS.dll
0x76e10000 - 0x76e35000 C:\WINDOWS\system32\adsldpc.dll
0x5b860000 - 0x5b8b4000 C:\WINDOWS\system32\NETAPI32.dll
0x76f60000 - 0x76f8c000 C:\WINDOWS\system32\WLDAP32.dll
0x76b20000 - 0x76b31000 C:\WINDOWS\system32\ATL.DLL
0x774e0000 - 0x7761c000 C:\WINDOWS\system32\ole32.dll
0x77120000 - 0x771ac000 C:\WINDOWS\system32\OLEAUT32.dll
0x76e80000 - 0x76e8e000 C:\WINDOWS\system32\rtutils.dll
0x71bf0000 - 0x71c03000 C:\WINDOWS\system32\SAMLIB.dll
0x77920000 - 0x77a13000 C:\WINDOWS\system32\SETUPAPI.dll
0x71a50000 - 0x71a8f000 C:\WINDOWS\system32\mswsock.dll
0x662b0000 - 0x66308000 C:\WINDOWS\system32\hnetcfg.dll
0x71a90000 - 0x71a98000 C:\WINDOWS\System32\wshtcpip.dll
0x76f20000 - 0x76f47000 C:\WINDOWS\system32\DNSAPI.dll
0x76fb0000 - 0x76fb8000 C:\WINDOWS\System32\winrnr.dll
0x76fc0000 - 0x76fc6000 C:\WINDOWS\system32\rasadhlp.dll
0x0ffd0000 - 0x0fff8000 C:\WINDOWS\system32\rsaenh.dll
0x769c0000 - 0x76a73000 C:\WINDOWS\system32\USERENV.dll
0x6d070000 - 0x6d1d7000 C:\Program Files\Java\jdk1.5.0_06\jre\bin\awt.dll
0x73000000 - 0x73026000 C:\WINDOWS\system32\WINSPOOL.DRV
0x76390000 - 0x763ad000 C:\WINDOWS\system32\IMM32.dll
0x5ad70000 - 0x5ada8000 C:\WINDOWS\system32\uxtheme.dll
0x73760000 - 0x737a9000 C:\WINDOWS\system32\ddraw.dll
0x73bc0000 - 0x73bc6000 C:\WINDOWS\system32\DCIMAN32.dll
0x73940000 - 0x73a10000 C:\WINDOWS\system32\D3DIM700.DLL
0x10000000 - 0x10005000 C:\WINDOWS\BricoPacks\Vista Inspirat\ObjectDock\DockShellHook.dll
0x74720000 - 0x7476b000 C:\WINDOWS\system32\MSCTF.dll
0x03510000 - 0x0351f000 C:\WINDOWS\BricoPacks\Vista Inspirat\YzToolbar\YzToolBar.dll
0x5d090000 - 0x5d127000 C:\WINDOWS\system32\COMCTL32.dll
0x7c9c0000 - 0x7e77e000 C:\WINDOWS\system32\shell32.dll
0x77f60000 - 0x77ff7000 C:\WINDOWS\system32\SHLWAPI.dll
0x773d0000 - 0x774d2000 C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9\comctl32.dll
0x6d2b0000 - 0x6d2ed000 C:\Program Files\Java\jdk1.5.0_06\jre\bin\fontmanager.dll
0x6d550000 - 0x6d559000 C:\Program Files\Java\jdk1.5.0_06\jre\bin\nio.dll
0x605d0000 - 0x605d9000 C:\WINDOWS\system32\mslbui.dll
0x71b20000 - 0x71b32000 C:\WINDOWS\system32\MPR.dll
0x75f60000 - 0x75f67000 C:\WINDOWS\System32\drprov.dll
0x71c10000 - 0x71c1e000 C:\WINDOWS\System32\ntlanman.dll
0x71cd0000 - 0x71ce7000 C:\WINDOWS\System32\NETUI0.dll
0x71c90000 - 0x71cd0000 C:\WINDOWS\System32\NETUI1.dll
0x71c80000 - 0x71c87000 C:\WINDOWS\System32\NETRAP.dll
0x75f70000 - 0x75f79000 C:\WINDOWS\System32\davclnt.dll
0x77b40000 - 0x77b62000 C:\WINDOWS\system32\appHelp.dll
0x76fd0000 - 0x7704f000 C:\WINDOWS\system32\CLBCATQ.DLL
0x77050000 - 0x77115000 C:\WINDOWS\system32\COMRes.dll
0x77c00000 - 0x77c08000 C:\WINDOWS\system32\VERSION.dll
0x76980000 - 0x76988000 C:\WINDOWS\system32\LINKINFO.dll
0x03bc0000 - 0x03c09000 C:\WINDOWS\system32\ntshrui.dll
VM Arguments:
jvm_args: -Dnetbeans.importclass=org.netbeans.upgrade.AutoUpgrade -Dnetbeans.accept_license_class=org.netbeans.license.AcceptLicense -Xms32m -Xmx128m -XX:PermSize=32m -XX:MaxPermSize=96m -Xverify:none -Dapple.laf.useScreenMenuBar=true -Dnetbeans.osenv=C:\DOCUME~1\M996F~1.KHA\LOCALS~1\Temp\nbenv3 -Dnetbeans.osenv.nullsep=true -Djdk.home=C:\Program Files\Java\jdk1.5.0_06 -Dnetbeans.home=C:\Program Files\netbeans-5.0\platform6 -Dnetbeans.dirs=C:\Program Files\netbeans-5.0\nb5.0;C:\Program Files\netbeans-5.0\ide6;C:\Program Files\netbeans-5.0\enterprise2;C:\Program Files\netbeans-5.0\harness -Dnetbeans.user=C:\Documents and Settings\M.Khalid\.netbeans\5.0 -Dnetbeans.system_http_proxy=DIRECT -Dsun.awt.keepWorkingSetOnMinimize=true
java_command: org/netbeans/Main --branding nb
Launcher Type: SUN_STANDARD
Environment Variables:
CLASSPATH=.
PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Common Files\Adobe\AGL;C:\Program Files\QuickTime\QTSystem\ ; C:\Program Files\Java\jre1.5.0_06\bin
USERNAME=M.Khalid
OS=Windows_NT
PROCESSOR_IDENTIFIER=x86 Family 6 Model 13 Stepping 6, GenuineIntel
--------------- S Y S T E M ---------------
OS: Windows XP Build 2600 Service Pack 2
CPU:total 1 family 6, cmov, cx8, fxsr, mmx, sse, sse2
Memory: 4k page, physical 514544k(100160k free), swap 1258580k(883052k free)
vm_info: Java HotSpot(TM) Client VM (1.5.0_06-b05) for windows-x86, built on Nov 10 2005 11:12:14 by "java_re" with MS VC++ 6.0Did you try asking Netbeans support too?
-
Repaint Problem in JInternalFrame!!!! help plz.
hi,
I have a question I have an application that has internal frames, Basically it is a MDI Application. I am using JDK 1.2.2 and windows 2000. The following example shows that when I drag my JInternalFrames only the border is shown and the contents are not shown as being dragged that's fine, but the application I am running have lot of components in my JInternalFrames. And when I drag the JInternalFrame my contents are not being dragged and that's what I want but when I let go the internalFrame it takes time to repaint all the components in the internalFrame. Is there any way I can make the repaint goes faster after I am done dragging the internalFrame. It takes lot of time to bring up the internalframe and it's components at a new location after dragging. Is there a way to speed up the repainting. The following example just shows how the outline border is shown when you drag the internalFrame. As there are not enough components in the internal frame so shows up quickly. But when there are lots of components specially gif images inside the internalframe it takes time.
/*************** MDITest ************/
import javax.swing.*;
* An application that displays a frame that
* contains internal frames in an MDI type
* interface.
* @author Mike Foley
public class MDITest extends Object {
* Application entry point.
* Create the frame, and display it.
* @param args Command line parameter. Not used.
public static void main( String args[] ) {
try {
UIManager.setLookAndFeel(
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel" );
} catch( Exception ex ) {
System.err.println( "Exception: " +
ex.getLocalizedMessage() );
JFrame frame = new MDIFrame( "MDI Test" );
frame.pack();
frame.setVisible( true );
} // main
} // MDITest
/*********** MDIFrame.java ************/
import java.awt.*;
import java.awt.event.*;
import java.io.Serializable;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
* A top-level frame. The frame configures itself
* with a JDesktopPane in its content pane.
* @author Mike Foley
public class MDIFrame extends JFrame implements Serializable {
* The desktop pane in our content pane.
private JDesktopPane desktopPane;
* MDIFrame, null constructor.
public MDIFrame() {
this( null );
* MDIFrame, constructor.
* @param title The title for the frame.
public MDIFrame( String title ) {
super( title );
* Customize the frame for our application.
protected void frameInit() {
// Let the super create the panes.
super.frameInit();
JMenuBar menuBar = createMenu();
setJMenuBar( menuBar );
JToolBar toolBar = createToolBar();
Container content = getContentPane();
content.add( toolBar, BorderLayout.NORTH );
desktopPane = new JDesktopPane();
desktopPane.putClientProperty("JDesktopPane.dragMode", "outline");
desktopPane.setPreferredSize( new Dimension( 400, 300 ) );
content.add( desktopPane, BorderLayout.CENTER );
} // frameInit
* Create the menu for the frame.
* <p>
* @return The menu for the frame.
protected JMenuBar createMenu() {
JMenuBar menuBar = new JMenuBar();
JMenu file = new JMenu( "File" );
file.setMnemonic( KeyEvent.VK_F );
JMenuItem item;
file.add( new NewInternalFrameAction() );
// file.add( new ExitAction() );
menuBar.add( file );
return( menuBar );
} // createMenuBar
* Create the toolbar for this frame.
* <p>
* @return The newly created toolbar.
protected JToolBar createToolBar() {
final JToolBar toolBar = new JToolBar();
toolBar.setFloatable( false );
toolBar.add( new NewInternalFrameAction() );
// toolBar.add( new ExitAction() );
return( toolBar );
* Create an internal frame.
* A JLabel is added to its content pane for an example
* of content in the internal frame. However, any
* JComponent may be used for content.
* <p>
* @return The newly created internal frame.
public JInternalFrame createInternalFrame() {
JInternalFrame internalFrame =
new JInternalFrame( "Internal JLabel" );
internalFrame.getContentPane().add(
new JLabel( "Internal Frame Content" ) );
internalFrame.setResizable( true );
internalFrame.setClosable( true );
internalFrame.setIconifiable( true );
internalFrame.setMaximizable( true );
internalFrame.pack();
return( internalFrame );
* An Action that creates a new internal frame and
* adds it to this frame's desktop pane.
public class NewInternalFrameAction extends AbstractAction {
* NewInternalFrameAction, constructor.
* Set the name and icon for this action.
public NewInternalFrameAction() {
super( "New", new ImageIcon( "new.gif" ) );
* Perform the action, create an internal frame and
* add it to the desktop pane.
* <p>
* @param e The event causing us to be called.
public void actionPerformed( ActionEvent e ) {
JInternalFrame internalFrame = createInternalFrame();
desktopPane.add( internalFrame,
JLayeredPane.DEFAULT_LAYER );
} // NewInternalFrameAction
} // MDIFrame
I'll really appreciate for any help.
Thank youHi
if you fill the ranges
r_rundate-sign = 'I'.
r_rundate-option = 'EQ'.
r_rundate-low = '20080613'.
r_rundate-high = '20080613'.
APPEND r_rundate.
EQ = 'equal', the select check the record with data EQ r_rundate-low.
change EQ with BT
BT = between
r_rundate-sign = 'I'.
r_rundate-option = 'BT'.
r_rundate-low = '20080613'.
r_rundate-high = '20080613'.
APPEND r_rundate.
reward if useful, bye -
I have a JScrollPane that I need to add multiple components to. That includes 5 JButtons, and 5 Jtree's.
I need to add all of the components at once, making the JTree's visible and invisible by clicking the JButton's. My first problem is when I try to add multiple objects to the JScrollPane using the default layout manager. The last object added is always stretched to fill the entire viewport. This makes the objects first added un-viewable. So I decided to first add all of the objects to a Box then add the Box to the scrollpane.
My second problem occurs when I make a JTree visible, aftering adding it to the Box. It draws the tree completely from top to bottom as it should, but clips the right end of titles on the nodes. The horizontal scroll adjusts enought so that you can scroll far enough to the right, but the titles are cut off.
If I add one of the JTree's directly to the JScrollPane it behaves as it should, showing the complete node titles.
I've tried revalidating, updating, and repainting without success.
So, first question is can multiple objects be added to a JScrollPane using the default layout manager, without having the last object hide the previously added objects?
Secondly, does anyone know why nodes in a JTree would be clipped when added to a Box then added the Box added to a JScrollPane. And more importantly how to fix it.
Any help would be appreciated,
Thanks,
JimHi there
Im not sure on exactly what you are trying to do.
But if you want multiple components in one JScrollPane
I would use a JPanel that I would add to the JScrollPane
On that JPanel I would then add my components.
I would also use GridBagLayout instead of any other layout manager. Thats because it is the most complex
layout manager and it will arrange the components as I whant.
If you whant to be able to remove a component from the view by making them invisible. I think I would consider
JLayeredPane.
on a JLayeredPane you add components on different layers. Each component is positionend exactly with setLocation or setBounds. This is the most exact thing to use. The JLayeredPane uses exact positioning of its components. which can be usefull when you use
several components that will be visible at different times
/Markus -
How to use JLayeredPane with LayoutManager
Hi!
I'm having problems with JLayeredPane. I simply cannot understand how to use it. I would like to have a button on top of my JDialog (The Dialog should have two components, a custom drawing panel and a JButton to close it with (want to keep the window undecorated, thus the need for the close-button)).
AboutDialog
|******Animation here***<- ------- CustomPanel
|**************************|
| *********and here*******|
| ******** ______*********|
| &here | Close | &here |<-----JDialog
| ******** ----------*********|
+------------------^---------- --+
...........................|
..........................JButton
This is what i tried, after finding out that JLayeredPane has a null layout:
class FilledLayeredPane extends JLayeredPane {
public FilledLayeredPane() {
super();
addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
compRes();
//Resize all components to fit
protected void compRes() {
Component[] comps = getComponents();
Rectangle bounds = getBounds();
for (int i=0; i<comps.length;i++)
((JComponent) comps).setBounds(bounds);
Then i added two panels with different z-order. One panel with the button, and also the CustomPanel.
However, the resize algorithm is ugly, and it doesn't work as it should at all. I'm getting really random behaviour from this...
How am i supposed to do?? I want the LayeredPane to layout the components i add to it! At least make sure that all added component fill up the size of the LayeredPane...
Plz help!Forgive me, that was bs. I get correct componentResized notificatiuons every single time.
The problem is: My manual updates of the JPanel inside the JLayeredPanel DO work, and the JPanel is resized correctly (otherwise I would see elements from behind shinig through).
BUT the JPanel doesn't always take the fact that it is manually resized as a reason to layout its components!!!
In my case, it works, as far as I've seen, EXACTLY EVERY SECOND TIME!!!
The solution is indeed VERY simple: After manually resizing an element with a layout that is non-null, call layout() on that element!!!
In my case,
jpanelXXX.setSize(size); jpanelXXX.layout();works wonders!!! -
JTable in JLayeredPane - resize table header cursor
Hey everybody, I have searched all over this forum and the net for an answer to this problem. I have a class that adds a JComponent to a JLayeredPane in the default layer. In another layer above the default layer is a JComponent that exists only to provide a 'pretty' image border with round corners that overlap the component below it. It works and looks very good. The only problem I have found is that if the JComponent that is added (in the default layer) is a JTable the cursor no longer changes to the resize cursor (<->) when mousing over the table header column edges. I can still resize the columns but I need to have the cursor change to indicate that the colums can be resized for user friendliness. I assume that the mouse events are getting trapped by the upper layer in the JLayeredPane and aren't reaching the JTable in the lower layer as they need to.
I have tried swapping the two layers but when I do that the corners of the component that I want to add the border to overlap over the nice round corners of the border which defeats the purpose.
If anyone has any suggestions, or even better a solution, that would be great!
Thanks,
Eriktable.getTableHeader().setVisible(false); will
help.This is necessary, but probably not quite sufficient for picky users. You may also want to set the min, max, and preferred dimensions of the table header to 0,0, otherwise you get what looks like a top-only border.
Michael Bushe -
Error using JsplitPane in JInternalFrame...help...
Hi,
If I am adding JSplitPane to JInternalFrame, I am getting the following run time error:
Any suggestions.. appreciated.
Thanks....
java.lang.NullPointerException: peer
at sun.awt.windows.WCanvasPeer.create(Native Method)
at sun.awt.windows.WComponentPeer.<init>(WComponentPeer.java:366)
at sun.awt.windows.WCanvasPeer.<init>(WCanvasPeer.java:26)
at sun.awt.windows.WToolkit.createCanvas(WToolkit.java:283)
at java.awt.Canvas.addNotify(Canvas.java:76)
at java.awt.Container.addNotify(Container.java:1579)
at javax.swing.JComponent.addNotify(JComponent.java:4015)
at java.awt.Container.addNotify(Container.java:1579)
at javax.swing.JComponent.addNotify(JComponent.java:4015)
at java.awt.Container.addNotify(Container.java:1579)
at javax.swing.JComponent.addNotify(JComponent.java:4015)
at java.awt.Container.addNotify(Container.java:1579)
at javax.swing.JComponent.addNotify(JComponent.java:4015)
at javax.swing.JRootPane.addNotify(JRootPane.java:483)
at java.awt.Container.addNotify(Container.java:1579)
at javax.swing.JComponent.addNotify(JComponent.java:4015)
at java.awt.Container.addImpl(Container.java:374)
at javax.swing.JLayeredPane.addImpl(JLayeredPane.java:201)
at java.awt.Container.add(Container.java:284)
at javax.swing.JLayeredPane.setLayer(JLayeredPane.java:343)
at javax.swing.JLayeredPane.setPosition(JLayeredPane.java:424)
at javax.swing.JLayeredPane.moveToFront(JLayeredPane.java:395)
at javax.swing.JInternalFrame.moveToFront(JInternalFrame.java:1024)
at javax.swing.JInternalFrame.toFront(JInternalFrame.java:1499)
at javax.swing.JInternalFrame.show(JInternalFrame.java:1457)
at java.awt.Component.show(Component.java:946)
at java.awt.Component.setVisible(Component.java:903)
at javax.swing.JComponent.setVisible(JComponent.java:1885)
at Client.Init(Client.java:835)
at Client.<init>(Client.java:659)
at Client.main(Client.java:974)Hi, please post some code, if this do not help you.
At line 835 in the class Client, Method init ( Client.Init(Client.java:835) ) the varibale peer is null.
Have you forgotten to intialize peer before Init is called??
Greetings
Michael -
Resizing Components in a JLayeredPane
Hello,
I'm brand new to Java (formerly a VB man). I'm creating an application where icons are displayed on a background image and can be dragged around the window. The background image and the icons need to resize with the window.
I've managed to get the back ground image to resize but can't work out how to get the icon images to resize as well. I also need to keep their relative positions as well.
I have three classes which extend JFrame, JLayeredPane and JPanel to construct the display. I have attached them below.
If anyone can help or at least point me in the right direction I would be very grateful indeed.
Best regards
Simon
package imagelayers;
import java.awt.*;
import java.awt.color.*;
import java.awt.event.*;
import javax.swing.*;
public class SecondFrame extends JFrame
private JLayeredPane m_layeredPane;
private MovingImage m_movImage1, m_movImage2, m_movImage3;
private BackgroundImage m_background;
public SecondFrame() {
super("Moving Images");
setLocation(10,10);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Load the background image in a JPanel
ImageIcon kcIcon = new ImageIcon("images/kclogo.gif");
m_background = new BackgroundImage(kcIcon);
setSize(kcIcon.getIconWidth(), kcIcon.getIconHeight());
m_movImage1 = new MovingImage("images/dukewavered.gif", 0);
m_movImage2 = new MovingImage("images/dukewavegreen.gif", 1);
m_movImage3 = new MovingImage("images/dukewaveblue.gif", 2);
m_background.add(m_movImage1 , JLayeredPane.DRAG_LAYER);
m_background.add(m_movImage2 , JLayeredPane.DRAG_LAYER);
m_background.add(m_movImage3 , JLayeredPane.DRAG_LAYER);
m_movImage2.topLayer = 2;
Container contentPane = getContentPane();
contentPane.add(m_background);
setVisible(true);
public static void main(String[] arguments)
JFrame frameTwo = new SecondFrame();
package imagelayers;
import java.awt.*;
import javax.swing.*;
public class BackgroundImage extends JLayeredPane
private Image m_backgroundImage;
public BackgroundImage(ImageIcon bg)
m_backgroundImage = bg.getImage();
setBorder(BorderFactory.createTitledBorder(""));
public void paintComponent(Graphics g)
g.drawImage(m_backgroundImage,0,0,getWidth(),getHeight(),this);
package imagelayers;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import java.awt.*;
import java.awt.event.*;
public class MovingImage extends JLabel implements MouseListener, MouseMotionListener
private Image m_theImage;
private ImageIcon m_theImageIcon;
private int nStartX, nStartY;
static int topLayer;
public MovingImage(String imgLocation, int layerNum)
addMouseListener(this);
addMouseMotionListener(this);
m_theImageIcon = new ImageIcon(imgLocation);
m_theImage = m_theImageIcon.getImage();
setBounds(0, 0, m_theImageIcon.getIconWidth(), m_theImageIcon.getIconHeight());
public void paintComponent(Graphics g)
g.drawImage(m_theImage,0,0,getWidth(),getHeight(),this);
public void mousePressed(MouseEvent e)
JLayeredPane imagesPane = (JLayeredPane)getParent();
imagesPane.setLayer(this,topLayer,0);
nStartX = e.getX();
nStartY = e.getY();
public void mouseMoved(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseDragged(MouseEvent e)
setLocation(getX() + e.getX() - nStartX, getY() + e.getY() - nStartY);
}Try useing the JFrames show() method or setVisible(true) method after you have added all the other components.
If that doesnt work use the JFrames validate() method, inherited from Container, after one of the previous methods.
Hope this helps -
Can anyone plz help me !!!!!!!!
This is the error i had while compiling my program...
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at function.MyFunc.y1(MyFunc.java:93)
at function.DiagramPanel.paintComponent(DiagramPanel.java:94)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
at java.awt.Container.paint(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
can anyone plz help me to find a solutionThis actually appears to be an error when you are running your program. It appears you have something you need to fix at line 93 of MyFunc.java. I can't help much more unless I can see some code.
-
Chess: java swing help need
Hi, I have just learn java swing and now creating a chess game. I have sucessfully create a board and able to display chess pieces on the board. By using JLayeredPane, I am able to use drag and drop for the piece. However, there is a problem which is that I can drop the chess piece off the board and the piece would disappear. I have try to solve this problem by trying to find the location that the chess piece is on, store it somewhere and check if the chess piece have been drop off bound. However, I could not manage to solve it. Also, I am very confuse with all these layer thing.
Any suggestion would be very helpful. Thanks in advance
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class ChessBoard extends JFrame implements MouseListener, MouseMotionListener
Object currentPosition;
Color currentColor;
Dimension boardSize = new Dimension(600, 600);
JLayeredPane layeredPane;
JPanel board;
JPanel box;
JLabel chessPiece;
int xAdjustment;
int yAdjustment;
public ChessBoard()
// Use a Layered Pane for this this application
layeredPane = new JLayeredPane();
getContentPane().add(layeredPane);
layeredPane.setPreferredSize( boardSize );
layeredPane.addMouseListener( this );
layeredPane.addMouseMotionListener( this );
// Add a chess board to the Layered Pane
board = new JPanel();
// set "board" to the lowest layer (default_layer)
layeredPane.add(board, JLayeredPane.DEFAULT_LAYER);
board.setLayout( new GridLayout(8, 8) );
board.setPreferredSize( boardSize );
board.setBounds(0, 0, boardSize.width, boardSize.height);
addShade();
addPiece();
public void addShade()
for (int i = 0; i < 64; i++)
box = new JPanel( new BorderLayout() );
board.add( box, BorderLayout.CENTER );
if( ((i / 8) % 2) == 0)
if( (i % 2) ==0)
box.setBackground(Color.lightGray);
} else {
box.setBackground( Color.white);
} else {
if( (i % 2) ==0)
box.setBackground(Color.white);
} else {
box.setBackground(Color.lightGray);
//Method for adding chess pieces to the board
public void addPiece()
// Add a few pieces to the board
//black pieces
for (int i = 0; i < 64; i++)
//adding black pieces
if (i < 8)
String fileName = i + ".gif";
JLabel blackPieces = new JLabel( new ImageIcon( fileName ) );
JPanel panel = (JPanel)board.getComponent( i );
panel.add( blackPieces );
//adding black pones
if ((i > 7) && (i < 16))
String fileName = "8.gif";
JLabel blackPones = new JLabel( new ImageIcon( fileName ) );
JPanel panel = (JPanel)board.getComponent( i );
panel.add( blackPones );
//jump to white position (Component 48)
if (i == 16) i = 48;
//adding white pones
if(( i > 47 ) && (i < 56))
JLabel whitePones = new JLabel( new ImageIcon("48.gif") );
JPanel panel = (JPanel)board.getComponent( i );
panel.add( whitePones );
//adding white pieces
if (i > 55)
String fileName = i + ".gif";
JLabel whitePieces = new JLabel( new ImageIcon( fileName ) );
JPanel panel = (JPanel)board.getComponent( i);
panel.add( whitePieces );
** Add the selected chess piece to the dragging layer so it can be moved
public void mousePressed(MouseEvent e)
chessPiece = null;
Component c = board.findComponentAt(e.getX(), e.getY());
c.setBackground(Color.red);
if (c instanceof JPanel) return;
Point parentLocation = c.getParent().getLocation();
xAdjustment = parentLocation.x - e.getX();
yAdjustment = parentLocation.y - e.getY();
chessPiece = (JLabel)c;
chessPiece.setLocation(e.getX() + xAdjustment, e.getY() + yAdjustment);
chessPiece.setSize(chessPiece.getWidth(), chessPiece.getHeight());
layeredPane.add(chessPiece, JLayeredPane.DRAG_LAYER);
** Move the chess piece around
public void mouseDragged(MouseEvent me)
if (chessPiece == null) return;
chessPiece.setLocation(me.getX() + xAdjustment, me.getY() + yAdjustment);
** Drop the chess piece back onto the chess board
public void mouseReleased(MouseEvent e)
Component c = board.findComponentAt(e.getX(), e.getY());
int x = (int)c.getBounds().getX();
int y = (int)c.getBounds().getY();
System.out.println(c.getLocation());
System.out.println(x + " "+ y);
c.setBackground(currentColor);
if (chessPiece == null) return;
chessPiece.setVisible(false);
if (c instanceof JLabel)
Container parent = c.getParent();
//remove the piece that is capture
parent.remove(0);
parent.add( chessPiece );
else
Container parent = (Container)c;
parent.add( chessPiece );
chessPiece.setVisible(true);
public void mouseClicked(MouseEvent e) {}
public void mouseMoved(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
private static void createAndShowGUI()
//Make sure we have nice window decorations
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new ChessBoard();
frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
//Display the window
frame.pack();
frame.setResizable( false );
frame.setLocationRelativeTo( null );
frame.setVisible(true);
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()
createAndShowGUI();
}import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class ChessBoardRx extends JFrame implements MouseListener, MouseMotionListener
Object currentPosition;
Color currentColor;
Dimension boardSize = new Dimension(600, 600);
JLayeredPane layeredPane;
JPanel board;
JPanel box;
JLabel chessPiece;
int xAdjustment;
int yAdjustment;
Container lastParent;
public ChessBoardRx()
// Use a Layered Pane for this this application
layeredPane = new JLayeredPane();
getContentPane().add(layeredPane);
layeredPane.setPreferredSize( boardSize );
layeredPane.addMouseListener( this );
layeredPane.addMouseMotionListener( this );
// Add a chess board to the Layered Pane
board = new JPanel();
// set "board" to the lowest layer (default_layer)
layeredPane.add(board, JLayeredPane.DEFAULT_LAYER);
board.setLayout( new GridLayout(8, 8) );
board.setPreferredSize( boardSize );
board.setBounds(0, 0, boardSize.width, boardSize.height);
addShade();
addPiece();
// populateBoard();
public void addShade()
for (int i = 0; i < 64; i++)
box = new JPanel( new BorderLayout() );
board.add( box, BorderLayout.CENTER );
if( ((i / 8) % 2) == 0)
if( (i % 2) ==0)
box.setBackground(Color.lightGray);
} else {
box.setBackground( Color.white);
} else {
if( (i % 2) ==0)
box.setBackground(Color.white);
} else {
box.setBackground(Color.lightGray);
//Method for adding chess pieces to the board
public void addPiece()
// Add a few pieces to the board
//black pieces
for (int i = 0; i < 64; i++)
//adding black pieces
if (i < 8)
String fileName = i + ".gif";
JLabel blackPieces = new JLabel( new ImageIcon( fileName ) );
JPanel panel = (JPanel)board.getComponent( i );
panel.add( blackPieces );
//adding black pones
if ((i > 7) && (i < 16))
String fileName = "8.gif";
JLabel blackPones = new JLabel( new ImageIcon( fileName ) );
JPanel panel = (JPanel)board.getComponent( i );
panel.add( blackPones );
//jump to white position (Component 48)
if (i == 16) i = 48;
//adding white pones
if(( i > 47 ) && (i < 56))
JLabel whitePones = new JLabel( new ImageIcon("48.gif") );
JPanel panel = (JPanel)board.getComponent( i );
panel.add( whitePones );
//adding white pieces
if (i > 55)
String fileName = i + ".gif";
JLabel whitePieces = new JLabel( new ImageIcon( fileName ) );
JPanel panel = (JPanel)board.getComponent( i);
panel.add( whitePieces );
private void populateBoard() {
int[][] pos = {
{ 9, 7, 5, 1, 3, 5, 7, 9 },
{ 8, 6, 4, 0, 2, 4, 6, 8 }
for(int j = 0; j < 8; j++) {
String fileName = "chessImages/" + pos[0][j] + ".jpg";
JLabel label = new JLabel( new ImageIcon( fileName ) );
JPanel panel = (JPanel)board.getComponent( j );
panel.add( label );
for(int j = 8; j < 16; j++) {
String fileName = "chessImages/" + 11 + ".jpg";
JLabel label = new JLabel( new ImageIcon( fileName ) );
JPanel panel = (JPanel)board.getComponent( j );
panel.add( label );
for(int j = 56, k = 0; j < 64; j++, k++) {
String fileName = "chessImages/" + pos[1][k] + ".jpg";
JLabel label = new JLabel( new ImageIcon( fileName ) );
JPanel panel = (JPanel)board.getComponent( j );
panel.add( label );
for(int j = 48; j < 56; j++) {
String fileName = "chessImages/" + 10 + ".jpg";
JLabel label = new JLabel( new ImageIcon( fileName ) );
JPanel panel = (JPanel)board.getComponent( j );
panel.add( label );
** Add the selected chess piece to the dragging layer so it can be moved
public void mousePressed(MouseEvent e)
chessPiece = null;
Component c = board.findComponentAt(e.getX(), e.getY());
c.setBackground(Color.red);
if (c instanceof JPanel) return;
lastParent = c.getParent();
Point parentLocation = c.getParent().getLocation();
xAdjustment = parentLocation.x - e.getX();
yAdjustment = parentLocation.y - e.getY();
chessPiece = (JLabel)c;
chessPiece.setLocation(e.getX() + xAdjustment, e.getY() + yAdjustment);
chessPiece.setSize(chessPiece.getWidth(), chessPiece.getHeight());
layeredPane.add(chessPiece, JLayeredPane.DRAG_LAYER);
** Move the chess piece around
public void mouseDragged(MouseEvent me)
if (chessPiece == null) return;
chessPiece.setLocation(me.getX() + xAdjustment, me.getY() + yAdjustment);
** Drop the chess piece back onto the chess board
public void mouseReleased(MouseEvent e)
Component c = board.findComponentAt(e.getX(), e.getY());
if(c == null) {
layeredPane.remove(chessPiece);
lastParent.add(chessPiece);
Rectangle r = lastParent.getBounds();
chessPiece.setLocation(r.x+xAdjustment, r.y+yAdjustment);
lastParent.validate();
lastParent.repaint();
return;
int x = (int)c.getBounds().getX();
int y = (int)c.getBounds().getY();
System.out.println(c.getLocation());
System.out.println(x + " "+ y);
c.setBackground(currentColor);
if (chessPiece == null) return;
chessPiece.setVisible(false);
if (c instanceof JLabel)
Container parent = c.getParent();
//remove the piece that is capture
parent.remove(0);
parent.add( chessPiece );
else
Container parent = (Container)c;
parent.add( chessPiece );
chessPiece.setVisible(true);
public void mouseClicked(MouseEvent e) {}
public void mouseMoved(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
private static void createAndShowGUI()
//Make sure we have nice window decorations
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new ChessBoardRx();
frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
//Display the window
frame.pack();
frame.setResizable( false );
frame.setLocationRelativeTo( null );
frame.setVisible(true);
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()
createAndShowGUI();
} -
Overlapping two JPanels on a JLayeredPane
I am having some problems overlapping two JPanels on a JLayeredPane for some reason only one of them shows when I compile the program! Any help would be greatly appreciated
The code is the following:
import java.lang.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SpaceBall
//To do the background just draw a JPanel inside another //JPanel just set the opacity of the outside one
//to false and let
//it hold all the components of the game
public static void main(String[] args)
//declaring the buttons
JButton test=new JButton("test");
JButton test1=new JButton("test1");
JButton test2=new JButton("test2");
//declaring and setting the properties of the frame
JFrame SpaceBall= new JFrame("Space Ball");
SpaceBall.setSize(700,650);
//declaring the Panels
JLayeredPane bgPanel= new JLayeredPane();
JPanel fgPanel= new JPanel();
JPanel topPanel= new JPanel();
JPanel sidePanel= new JPanel();
JPanel lowPanel= new JPanel();
JPanel masterPanel= new JPanel();
//adding the buttons to the corresponding panels
fgPanel.add(test1);
sidePanel.add(test2);
topPanel.add(test);
ImageIcon background= new ImageIcon("images/background.jpg");
JLabel backlabel = new JLabel(background);
backlabel.setBounds(0,0,background.getIconWidth(),background.getIconHeight());
backlabel.add(test1);
bgPanel.add(backlabel, new Integer(0));
fgPanel.setOpaque(false);
bgPanel.add(fgPanel, new Integer(100));
bgPanel.moveToFront(fgPanel);
//adding bgPanel and sidePanel to lowPanel
lowPanel.setLayout(new GridLayout(1,2));
lowPanel.add(bgPanel);
lowPanel.add(sidePanel);
//adding the Panels to the masterPanel
masterPanel.setLayout(new GridLayout(2,1));
masterPanel.add(topPanel);
masterPanel.add(lowPanel);
//getting the container of SpaceBall and adding the Panels to it
Container cp=SpaceBall.getContentPane();
cp.add(masterPanel);
//displaying everything
SpaceBall.show();
WindowListener ClosingTheWindow=new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
SpaceBall.addWindowListener(ClosingTheWindow);Take a look at the section from the Swing tutorial titled "How to Use Layered Panes". It has a sample program:
http://java.sun.com/docs/books/tutorial/uiswing/components/layeredpane.html -
JLayeredPane with JScrollPane inside
Hi all,
I am making an applet with a fairly complex gui. The main part is a content window that has a jpanel with another jpanel and a jscrollpane inside, each of which have a bunch of components. From there I wanted to add a help window that popped up when you hit the help button. What I did is I got the JLayeredPane from the applet using getLayeredPane(), and I added the help window to the popup layer, and the content window to the default layer. I'm using a null layout and manually setting the bounds of everything. All the panels draw correctly, but when I open the help window, it displays inside the JScrollPane; i.e. it moves when I scroll, and the contents of the scroll pane are displayed on top of the help window. Here is some of my code, if I wasn't clear:
//this grabs the applet's layered pane. The wrapper pane (with all the traces)
//is on the default layer, and the help window (and any other popups) will go in the popup layer
appletLayered = getLayeredPane();
appletLayered.setLayout(null);
//create the help window that will be displayed when someone presses help
helpWindow = new HelpWindow(getCodeBase().toString());
appletLayered.add(helpWindow, JLayeredPane.POPUP_LAYER);
helpWindow.setBounds(50,50,400,450);
appletLayered.add(wrapperPane, JLayeredPane.DEFAULT_LAYER);
wrapperPane.setBounds(0,20,700,550);Does anyone know why it is doing this? Should I just do this whole thing a different way, or is there an easy solution that I'm missing.Swing related questions should be posted in the Swing forum.
From there I wanted to add a help window* that popped up when you hit the help button.Then use a JDialog (or a JWindow), not a layered pane.
If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
Maybe you are looking for
-
Can't Move Objects, Can't Uninstall CC
I'm running Adobe CC on Mac OS X Yosemite. I've got variations on the same problem, but the main thrust is: I can't move objects. More detailed: I booted up InDesign this morning and started working in it. All of a sudden, I couldn't move any of my o
-
Wrong pictures for albums in my iphone but correkt picture in itunes
Hi. In my iPhone 4 all albums in the musicplayer has wrong picture but in iTunees in my computer it is correkt. Haw can i correct this?
-
How do I register a new ipad mini?
How do I register a new ipad mini? Is it even necessary? tkyou
-
Please help I'm really trying to learn it as fast as possible? I've posted the file with all my screen shots going through the enitre process of me creating the LSMW file.
-
No luck buying songs on itunes
It's been over a year since I was cut off from buying music on itunes. Here are some facts and maybe someone can figure it out. I'm the administrator on my computer. I allow the rest of my family to use my computer, but they must log in under their n