English 中文(简体)
问题和行动问题
原标题:doLayout() and ActionListener questions

我对联合工作组来说是新的,因此,我宽恕我,可能有些真正开始的问题。

After reading the tutorial on how to use top level containers, I tried the following code inside the actionPerformed event in a button:

private void colgarActionListener(java.awt.event.ActionEvent evt) {

        auxButton = new JButton();
        auxButton.setSize(100,30);
        auxButton.setText("Me button");
        getContentPane().add(auxButton);
        getContentPane().doLayout();


}

如你所期望的那样,它不工作。 纽伦就没有出现。 如果我尝试一 thing,例如:

getContentPane().setBackground(Color.red);

instead of

getContentPane().doLayout();

它运作。 我做了什么错误?

And the last one: if I write a class which works as a custom ActionListener (with its constructor with parameters), where should I put it? As a private class inside the GUI code? It just feels so dirty... Or as a public class inside another package. maybe?

Thank you very much.

问题。

Martín。

最佳回答

各位将想读一下布局管理人员如何工作以及如何为此利用他们,是使用Swaing(而不是通过方式使用JSing)的关键之一。 Tutorial的Layout管理员是一个很大的开端。

一、避免使用无效格式和<代码> 而另一方面,内容Pane通常使用边境停工。 此外,我从未看到过之前使用的<代码>doLayout()。 通常见<代码>validate(>或revalidate(>,后加repaint(>)在更换集装箱部件后向集装箱发出。

问题回答

是的,“行动生计”通常不仅作为私人类别,而且作为匿名类别,在使用现场进行。 匿名类别是你写字时。

x.addActionListener(new ActionListener() { public void actionPerformed(Event e) {
   ... stuff to do ...
}});




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签