有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Swing GUI在用户输入文本时移动

我正在尝试做一个相当基本的swing GUI,用户可以输入url、选择本地文件位置等。我使用多个布局管理器,包括boxlayout、borderlayout和flowlayout。代码如下。 我的问题是,当用户将文本放入optionsTxt jtextarea时,一些组件正在移动。有人知道我应该从哪里开始阻止这种事情发生吗

Setup menu bar
    JButton menu_File = new JButton("File");
    JButton menu_Edit = new JButton("Edit");
    JToolBar toolBar = new JToolBar();
    toolBar.add(menu_File);
    toolBar.add(menu_Edit);

    //Setup options area
    JPanel options = new JPanel();
    options.setBorder(BorderFactory.createTitledBorder("Options"));
    BoxLayout layout_Options = new BoxLayout(options, BoxLayout.Y_AXIS);
    options.setLayout(layout_Options);
    JLabel optionsLblURL = new JLabel("Enter URL:");
    optionsTxtUrl = new JTextArea(1,15);        
    JLabel chooseDestLbl = new JLabel("Choose save location:");
    chooseDest = new JButton("Browse");
    chooseDest.addActionListener(this);
    options.add(optionsLblURL);
    options.add(optionsTxtUrl);
    options.add(chooseDestLbl);
    options.add(chooseDest);

    //Setup launch area
    JPanel launch = new JPanel();
    launch.setBorder(BorderFactory.createTitledBorder("Launch"));
    launchBtnStart = new JButton("Start Download");
    launchBtnStart.setVerticalAlignment(SwingConstants.CENTER);
    launchBtnStart.setHorizontalAlignment(SwingConstants.CENTER);
    launchBtnStart.addActionListener(this);
    launch.add(launchBtnStart);

    //Setup reporting area
    JPanel logging = new JPanel();
    logging.setBorder(BorderFactory.createTitledBorder("Log"));
    BoxLayout layout_Logging = new BoxLayout(logging, BoxLayout.Y_AXIS);
    logging.setLayout(layout_Logging);
    JTextArea loggingTxt = new JTextArea(3,10);
    loggingTxt.setEditable(false);
    logging.add(pb);
    logging.add(loggingTxt);

    //Add components to window        
    BorderLayout borderLayout = new BorderLayout();
    setLayout(borderLayout);
    add("North", toolBar);
    add("West", options);
    add("East", launch);
    add("South", logging);

    setVisible(true);

共 (0) 个答案