简体   繁体   English

Java应用程序不响应代码更改

[英]Java application not responding to code changes

I am trying to implement a simple interface in java but It has become unresponsive to code changes,for example setting a new location to for a combo box does not change the location of it. 我正在尝试在Java中实现一个简单的接口,但是它对代码更改没有反应,例如,将新位置设置为组合框不会更改它的位置。 My code is: 我的代码是:

public class Interfata extends JFrame
{
    static JFrame window= new JFrame("Aplicatie bancara");
    static JButton persoana_button= new JButton("PERSOANE");
    static JButton cont_button= new JButton("CONTURI");
    public static void main( String[] args )
    {

        window.setBounds(10, 10, 300, 200);
        JPanel panel_main= new JPanel();
        window.add(panel_main);

        cont_button.setBounds(90, 150, 100, 70);
        panel_main.add(cont_button);
        cont_button.addActionListener(new ActionListener(){ 
            public void actionPerformed(ActionEvent arg0) { 
                 JFrame view = new JFrame("Accounts");
                 JPanel pane= new JPanel();
            String[] account_type=
                {"savings", "spending"};
            JComboBox petList = new JComboBox(account_type);
            petList.setSelectedIndex(1);
            petList.addActionListener(new ActionListener()
                    {
                public void actionPerformed(ActionEvent arg0) {
                    // TODO Auto-generated method stub

                }
                    });
            petList.setSize(50, 50);
            petList.setLocation(400,320);   
                pane.add(petList);
                view.setDefaultCloseOperation(view.DISPOSE_ON_CLOSE);
                view.setBounds(10,10,400,400);
                view.add(pane);
                view.setVisible(true);

            }});


        window.setVisible(true);

As shown in code my window is set to the size, aproximately, 400x400 and I have set the location to the combo box at 400, 320 which should place it outside the frame, but it stays stuck in the middle. 如代码中所示,我的窗口被设置为大约400x400的大小,并且我已将组合框的位置设置为400、320,该组合框应将其放置在框架之外,但仍停留在中间。 在此处输入图片说明

I am using eclipse neon oxygen., and coding in a Maven project. 我正在使用日食氖氧,并在Maven项目中进行编码。 just after changing my code I got this message: 更改代码后,我收到以下消息:

some code changes cannot be hot swapped into a running virtual machine 某些代码更改无法热交换到正在运行的虚拟机中

I have tried restarting eclipse, changing the workspace location and completely starting a new with the project. 我尝试过重新启动eclipse,更改工作区位置并完全从项目开始新的尝试。 However it still won't move. 但是它仍然不会移动。

You have a running copy of your program, that was launched before you made your changes. 您有程序的运行副本,该副本是在进行更改之前启动的。 This running copy is not the same process as your Eclipse IDE. 此运行副本与Eclipse IDE的过程不同。

You need to stop this running copy, and then relaunch the new copy which is compiled on disk, but for one reason or another, could not be patched into the copy that you had already launched. 您需要停止此正在运行的副本,然后重新启动在磁盘上编译的新副本,但是由于某种原因而无法将其修补到已经启动的副本中。

To find your running copy, you may need to use your operating system's process list and find the correct program (typically containing the word 'java' in the program command line) to terminate. 要查找正在运行的副本,您可能需要使用操作系统的进程列表,并找到要终止的正确程序(通常在程序命令行中包含单词“ java”)。

Once you kill that program, you should be able to relaunch it, and then you should see the changes saved to disk in your last successful compile. 终止该程序后,应该可以重新启动该程序,然后应该在上一次成功的编译中看到更改已保存到磁盘。

This is mainly related to LayoutManager: 这主要与LayoutManager有关:

  1. You have added combo box to panel 您已将组合框添加到面板
  2. JPanel have default layout as FlowLayout JPanel的默认布局为FlowLayout
  3. FlowLayout adds controls by default with center alignment of container. FlowLayout默认情况下添加控件,使容器居中对齐。
  4. FlowLayout do not adhere to setLocation(x,y) hence you don't see any effect FlowLayout不遵守setLocation(x,y)因此您看不到任何效果

With your existing code, if you set the pane's layout to null ie pane.setLayout(null) , you will surely get the desired result, however null layout is not recommended . 使用现有代码,如果将pane's布局设置为nullpane.setLayout(null) ,则肯定会获得所需的结果,但是不建议使用null布局 Perhaps you may consider using other layouts SpringLayout or GroupLayout but this would require an IDE as manual coding would be a pain. 也许您可能考虑使用其他布局 SpringLayoutGroupLayout但这需要IDE,因为手动编码会很GroupLayout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM