Java JEditorPane不能正常工作,如果我实现了它,那么一切都会出错

Java JEditorPane不能正常工作,如果我实现了它,那么一切都会出错,java,browser,jeditorpane,Java,Browser,Jeditorpane,我和我的朋友在查兰格,为了制作一个更好的程序,他决定制作一个痛苦工具,而我决定制作一个网络浏览器。我目前正在尝试实现这些字段。如果我添加一个地址栏和一个按钮,一切都会按指示进行,但当我放置一个JEditorPane时,屏幕上就不会显示它要显示的内容 代码中没有JEditorPane(一切正常): 图像没有JEditorPanehttp,一切正常: 使用JEditorPane编写代码(并非所有操作都按说明进行): 使用JEditorPane拍摄图像时,一切都无法正常工作: 我试着删除一些.set,

我和我的朋友在查兰格,为了制作一个更好的程序,他决定制作一个痛苦工具,而我决定制作一个网络浏览器。我目前正在尝试实现这些字段。如果我添加一个地址栏和一个按钮,一切都会按指示进行,但当我放置一个JEditorPane时,屏幕上就不会显示它要显示的内容

代码中没有JEditorPane(一切正常):

图像没有JEditorPanehttp,一切正常:

使用JEditorPane编写代码(并非所有操作都按说明进行):

使用JEditorPane拍摄图像时,一切都无法正常工作:


我试着删除一些.set,我试着在线查看,我也试着只运行JEditorPpane,但我似乎无法为它设置变量(如位置、大小等)。

您遇到了问题,因为
FlowLayout
管理器,这是
JPanel
的默认布局管理器,它正在自行决定如何管理
holder
面板及其内容的布局

  • 利用适当的布局。有关更多详细信息,请参阅
  • 在事件调度线程的上下文中启动UI。有关更多详细信息,请参阅
  • 布局、打包,然后使框架可见
  • 对于可能超出窗口可见要求的内容,应使用
    JScrollPane
    s。有关更多详细信息,请参阅


JFrame
上,调用
add()
pack()
,然后调用
setVisible()
。将setPack和setVisible放在代码的按钮中,或者它对执行没有任何影响?如何使JTextField随JFrame的扩展而扩展?它不会影响性能,但会使您添加到帧中的组件在帧第一次可见时可见,否则您需要在帧上调用
validate
,以强制更新,这将导致性能下降。要在整个框架中展开
JTextField
,需要使用不同的布局管理器。类似于
GridBagLayout
的东西可以完成这项工作。
import java.awt.*;
import javax.swing.*;
public class browserPannel
{
    public static void main(String[] arg)
    {
        JFrame browser = new JFrame("A Nun In A Weelchair");
        browser.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        browser.setLocationRelativeTo(null);
        browser.setSize(1000,700);
        browser.setVisible(true);
        browser.setResizable(false);

        JTextField url = new JTextField();
        url.setSize(890,30);
        url.setVisible(true);
        url.setLocation(15,15);

        JPanel holder = new JPanel();
        holder.setBackground(Color.lightGray);
        holder.setSize(1000,700);

        JButton send = new JButton("Send");
        send.setSize(75,30);
        send.setVisible(true);
        send.setLocation(906,15);

        //JEditorPane htmlc = new JEditorPane();
        //htmlc.setBackground(Color.red);
        //htmlc.setEditable(true);
        //htmlc.setContentType("text/html");
        //htmlc.setSize(500,500);
        //htmlc.setVisible(true);
        //htmlc.setLocation(15,50);




        holder.add(url);
        holder.add(send);
        //holder.add(htmlc);
        browser.getContentPane().add(holder);
    }
}
import java.awt.*;
import javax.swing.*;
public class browserPannel
{
    public static void main(String[] arg)
    {
        JFrame browser = new JFrame("A Nun In A Weelchair");
        browser.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        browser.setLocationRelativeTo(null);
        browser.setSize(1000,700);
        browser.setVisible(true);
        browser.setResizable(false);

        JTextField url = new JTextField();
        url.setSize(890,30);
        url.setVisible(true);
        url.setLocation(15,15);

        JPanel holder = new JPanel();
        holder.setBackground(Color.lightGray);
        holder.setSize(1000,700);

        JButton send = new JButton("Send");
        send.setSize(75,30);
        send.setVisible(true);
        send.setLocation(906,15);

        JEditorPane htmlc = new JEditorPane();
        htmlc.setBackground(Color.red);
        htmlc.setEditable(true);
        htmlc.setContentType("text/html");
        htmlc.setSize(500,500);
        htmlc.setVisible(true);
        htmlc.setLocation(15,50);




        holder.add(url);
        holder.add(send);
        holder.add(htmlc);
        browser.getContentPane().add(holder);
    }
}
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;

public class BrowserPannel {

    public static void main(String[] arg) {
        JFrame browser = new JFrame("A Nun In A Weelchair");
        browser.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        browser.setLocationRelativeTo(null);

        JTextField url = new JTextField(20);

        JPanel header = new JPanel();
        header.setBackground(Color.lightGray);

        JButton send = new JButton("Send");

        JEditorPane htmlc = new JEditorPane();
        htmlc.setBackground(Color.red);
        htmlc.setEditable(true);
        htmlc.setContentType("text/html");

        header.add(url);
        header.add(send);
        browser.getContentPane().add(header, BorderLayout.NORTH);
        browser.getContentPane().add(new JScrollPane(htmlc));

        browser.pack();
        browser.setVisible(true);

    }
}