我在设置文本后设置JTextArea的背景颜色时遇到问题.代码如下:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class Test extends JFrame {
private JTextArea area;
public Test() {
this.setLayout(new BorderLayout());
this.add(this.area = new JTextArea(), BorderLayout.CENTER);
this.add(new JButton(clickAction), BorderLayout.SOUTH);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setPreferredSize(new Dimension(500, 200));
this.pack();
this.area.setText("this is just a test");
this.setVisible(true);
}
Action clickAction = new AbstractAction("Click") {
@Override
public void actionPerformed(ActionEvent e) {
area.setBackground(new Color(0, 0, 123, 138));
// repaint();
}
};
public static void main(String[] args) { …Run Code Online (Sandbox Code Playgroud) 从 ActiveMQ 连接创建会话对象时,有没有设置超时的方法?
我使用的代码如下所示:
ConnectionFactory factory = Settings.getJmsConnectionFactory(ip);
connection = factory.createConnection();
// insert timeout here
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(Settings.Topic);
MessageConsumer consumer = session.createConsumer(topic);
consumer.setMessageListener(this);
connection.start();
Run Code Online (Sandbox Code Playgroud)
只要消息服务器已经启动,这就可以正常工作。否则 createSession 调用将阻塞。我可以在另一个线程上执行它以避免应用程序阻塞,但我想我会问是否有一种“更干净”的方法来做到这一点。
干杯,马克斯