我正在尝试在另一个JPanel中设置Jlay的Boxlayout.但我无法弄清楚如何解决这个错误
Exception in thread "main" java.awt.AWTError: BoxLayout can't be shared
at javax.swing.BoxLayout.checkContainer(BoxLayout.java:464)
at javax.swing.BoxLayout.invalidateLayout(BoxLayout.java:248)
at javax.swing.BoxLayout.addLayoutComponent(BoxLayout.java:281)
at java.awt.Container.addImpl(Container.java:1120)
at java.awt.Container.add(Container.java:410)
at chatmsg1.ProfilePanel.<init>(ProfilePanel.java:63)
at chatmsg1.ProfilePanel.main(ProfilePanel.java:108)
Java Result: 1
Run Code Online (Sandbox Code Playgroud)
这是守则!任何帮助将不胜感激 !!
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.management.ImmutableDescriptor;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
class ProfilePanel extends JPanel{
JLabel jl1,jl2,jl3,jl4,jl5,jl6,jl7,jl8,jl9,jl10;
ImagePanel ip= new ImagePanel();
JPanel jp1= new JPanel(new BorderLayout());
JPanel labelpanel;
static int textwidth=100;
static String uname, uage, usex, udept, uheight="jjhkjhiuhiuhiuhiuhihihuihiuhiuhuhiuhiuhihihiuhhihhuhih",ubatch, ucontact, uemail;
public ProfilePanel() {
this.labelpanel …Run Code Online (Sandbox Code Playgroud) 我正在尝试添加一个将JPanel扩展到另一个JPanel的图像面板.这对我来说效果不佳.图像面板的绘制功能不会在Jpanel中调用,但在JFrame中可以正常工作.任何想法或帮助将不胜感激.
import javax.swing.*;
import java.awt.*;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
class ImagePanel extends JPanel
{
int g_h=10,g_w=10;
int width=50,height=50;
int cornerradius;
Image castle;
Dimension size;
protected int x1,y1;
Color c1=new Color(255, 0, 0);
Rectangle rec;
boolean b=false;
boolean imboo=false;
boolean roundb= false;
Graphics g= this.getGraphics();
protected int strokeSize = 1;
protected Color shadowColor = Color.BLACK;
boolean shadowed = false;
public ImagePanel()
{
//super();
setOpaque(false);
setLayout(null);
System.out.println("it executed");
}
public ImagePanel(int x, int y)
{
setSize(x, y);
}
public void setSize(int x,int …Run Code Online (Sandbox Code Playgroud)