小编aym*_*ric的帖子

创建一个检查属性窗口,按钮驱动为JDialog

我原来问的并没有明确说明我的问题/问题,所以我会更好地解释.我有一个JButton,设置一个JDialog可见.JDialog将WindowListener其设置为在windowDeactivated()事件中不可见,该事件在用户在对话框外单击时触发.按钮ActionListener检查对话框是否为可见,如果为true则隐藏它,如果为false则显示该对话框.

windowDeactivated()只要用户在对话框外单击,就会始终触发是否单击按钮.我遇到的问题是当用户单击按钮关闭对话框时.该对话框由关闭WindowListener,然后ActionListener尝试显示它.

如果windowDeactivated()没有setVisible(false),则对话框仍然打开,但在父窗口后面.我要求的是如何访问里面的点击位置windowDeactivated().如果我知道用户点击了按钮并且windowDeactivated()可以跳过隐藏对话框,那么按钮ActionListener会看到它仍然可见并隐藏它.

public PropertiesButton extends JButton {

    private JDialog theWindow;

    public PropertiesButton() {
        theWindow = new JDialog();
        theWindow.setUndecorated(true);
        theWindow.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        theWindow.add(new JMenuCheckBoxItem("Something"));
        theWindow.addWindowListener(new WindowListener() {
            // just an example, need to implement other methods
            public void windowDeactivated(WindowEvent e) {
                theWindow.setVisible(false);
            }
        });
        this.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (theWindow.isVisible()) {
                    theWindow.setVisible(false);
                } else { …

java swing jdialog jbutton jpopupmenu

8
推荐指数
1
解决办法
1423
查看次数

GridLayout上的FlowLayout无法正常工作

我正在尝试创建一个刽子手游戏,到目前为止,它正在进行中,但布局设计似乎并没有落实到位!字母表应该以FlowLayoutHangman图片顶部的顺序结束,底部有"重启","帮助","添加新单词"和"退出"按钮!我究竟做错了什么?

刽子手

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class Hangman extends JFrame
{
    int i = 0;
    static JPanel panel;
    static JPanel panel2;
    static JPanel panel3;

    public Hangman()
    {
        JButton[] buttons = new JButton[26];

        panel = new JPanel(new FlowLayout());
        panel2 = new JPanel();
        panel3 = new JPanel();

        JButton btnRestart = new JButton("Restart");
        btnRestart.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e)
            {

            }
        });

        JButton btnNewWord = new JButton("Add New Word");
        btnNewWord.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e)
            {
                try …
Run Code Online (Sandbox Code Playgroud)

java swing jpanel jframe layout-manager

8
推荐指数
1
解决办法
2242
查看次数

重写Adapter.getView

我是android编程的新手,并且使用Adapters(for a ListView)做了第一步.

覆盖Adapter.getView我经常看到这样的事情:

public View getView(int position, View convertView, ViewGroup parent) {

    View itemView = null;

    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) parent.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        itemView = inflater.inflate(R.layout.table_row, null);
    } else {
        itemView = convertView;
    }

    // play with itemView

    return itemView;
}
Run Code Online (Sandbox Code Playgroud)

我的问题是反对这一点:

public View getView(int position, View convertView, ViewGroup parent) {

    View itemView = super(position, convertView, parent);

    // play with itemView

    return itemView;
}
Run Code Online (Sandbox Code Playgroud)

这似乎对我有用,但我确信我有一个很重要的一点:D

感谢您阅读并抱歉我的英语不好......

android adapter android-listview

8
推荐指数
1
解决办法
1万
查看次数

使用Jenkins的SVN"不受版本控制"失败

我在Jenkins有一个项目,有许多SVN存储库可供使用.每当我构建时,工作区清理后的第一个构建都会失败,并出现如下错误.没有改变任何东西,下一个构建将是成功的.

如果我将项目设置为在构建之前始终清理工作区,它将始终失败.每次都有不同的SVN存储库.

我尝试转移到SVN 1.6,尝试验证HTTPS证书是否正常,不确定还有什么要查找的?

ERROR: Failed to parse svn info for     https://subversion.assembla.com/svn/<PROJECT NAME HIDDEN>/trunk
org.tmatesoft.svn.core.SVNException: svn:     '/tmp/data/hudson/jobs/Build_ISO/workspace/ch.ethz.ssh2' is not under version control
    at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:64)
    at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:51)
    at org.tmatesoft.svn.core.wc.SVNWCClient$13.handleError(SVNWCClient.java:3314)
    at org.tmatesoft.svn.core.internal.wc.admin.SVNWCAccess.walkEntries(SVNWCAccess.java:758)
    at org.tmatesoft.svn.core.internal.wc.admin.SVNWCAccess.walkEntries(SVNWCAccess.java:741)
at org.tmatesoft.svn.core.wc.SVNWCClient.crawlEntries(SVNWCClient.java:3294)
at org.tmatesoft.svn.core.wc.SVNWCClient.doInfo(SVNWCClient.java:2498)
at org.tmatesoft.svn.core.wc.SVNWCClient.doInfo(SVNWCClient.java:2865)
at hudson.scm.SubversionSCM$BuildRevisionMapTask.invoke(SubversionSCM.java:1023)
at hudson.scm.SubversionSCM$BuildRevisionMapTask.invoke(SubversionSCM.java:1001)
at hudson.FilePath.act(FilePath.java:832)
at hudson.FilePath.act(FilePath.java:814)
at hudson.scm.SubversionSCM.checkout(SubversionSCM.java:685)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1212)
at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:579)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:468)
at hudson.model.Run.run(Run.java:1410)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:238)
Caused by: org.tmatesoft.svn.core.SVNErrorMessage: svn: '/tmp/data/hudson/jobs/Build_ISO/workspace/ch.ethz.ssh2' is not under version control
at org.tmatesoft.svn.core.SVNErrorMessage.create(SVNErrorMessage.java:163)
at org.tmatesoft.svn.core.SVNErrorMessage.create(SVNErrorMessage.java:118)
... 17 more
Run Code Online (Sandbox Code Playgroud)

svn hudson jenkins

7
推荐指数
2
解决办法
9650
查看次数

在詹金斯工作失败

这个问题可能听起来很奇怪,但我如何让工作失败?

我有一个python脚本,使用scons编译少量文件,并作为jenkins工作运行.该脚本测试编译器是否可以构建x64或x86二进制文件,如果它无法执行其中一个操作,我希望该作业失败.

例如:如果我在64位系统上运行我的脚本并且无法编译64位.我可以在脚本中做些什么可能导致失败吗?

python jenkins

7
推荐指数
2
解决办法
1万
查看次数

为什么Lucene在索引大文件时会导致OOM?

我正在使用Lucene 2.4.0和JVM(JDK 1.6.0_07).OutOfMemoryError: Java heap space在尝试索引大型文本文件时,我一直在接收.

示例1:索引5 MB文本文件的内存不足,最大64 MB.堆大小.所以我增加了最大值.堆大小为512 MB.这适用于5 MB的文本文件,但Lucene仍然使用84 MB的堆空间来执行此操作.为什么这么多?

FreqProxTermsWriterPerField根据JConsole和Eclipse Ganymede的TPTP Memory Profiling插件,该类似乎是迄今为止最大的内存消费者.

示例2:索引62 MB文本文件的内存不足,最大512 MB.堆大小.增加最大值 堆大小为1024 MB,但Lucene在执行此操作时使用了826 MB的堆空间.似乎还有太多的内存被用来做这件事.我确定较大的文件会导致错误,因为它似乎相关.

我在拥有2 GB RAM的Windows XP SP2平台上.那么索引大文件的最佳做法是什么?这是我正在使用的代码段:

// Index the content of a text file.
private Boolean saveTXTFile(File textFile, Document textDocument) throws MyException {           

        try {             

              Boolean isFile = textFile.isFile();
              Boolean hasTextExtension = textFile.getName().endsWith(".txt");

              if (isFile && hasTextExtension) {

                    System.out.println("File " + textFile.getCanonicalPath() + " is being indexed");
                    Reader textFileReader = new FileReader(textFile);
                    if (textDocument == null) …
Run Code Online (Sandbox Code Playgroud)

lucene indexing file

5
推荐指数
1
解决办法
7483
查看次数

在spring中运行时更改bean属性/值

我使用的是spring mvc + hibernate +两个数据库

例如:我创建了2个sessionFactories.sessionFactory1(使用datasource1)和sessionFactory2(使用datasource2).

是否可以在运行时更改sessionFactory1或更改sessionFactory2sessionFactory,以便dao/s引用它们.sessionFactory已经自动连接到所有dao/s.

我正在寻找它我认为@Configuration可以帮助我,但我不确定.

我正在尝试AbstractRoutingDataSource,但不认为它有帮助.

java spring hibernate multiple-databases

5
推荐指数
1
解决办法
2632
查看次数

JLabel不会显示图像

我正在使用 Java 创建一个 Tic-Tac-Toe 游戏。现在,我有了它,因此当您单击一个按钮时,该按钮JButton将从 中删除JPanelJLabel添加一个包含 X 或 O 图像的图像,并且JPanel将重新绘制。但是,当我单击该按钮时,图像不会显示,但按钮消失。

创建按钮和JLabel/ Image

package tictactoe;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.ImageIcon;

public class TicTacToe implements ActionListener
{
private JFrame holder = new JFrame();
private GridLayout layout = new GridLayout(3,3);
private FlowLayout panel = new FlowLayout(FlowLayout.CENTER);
private JPanel p11, p12, p13, p21, p22, p23, p31, p32, p33;
private JButton b1, b2, b3, b4, b5, b6, b7, b8, b9;
private …
Run Code Online (Sandbox Code Playgroud)

java swing jlabel jbutton

5
推荐指数
1
解决办法
843
查看次数

如何在TYPE_3BYTE_BGR中获取jpeg图像的rgb值?

我有这个图像:

谷歌图片

我想在一个中提取这个图像的RGB值int[].这是我到目前为止为PNG图像所做的事情:

File f = new File("t.jpg");
BufferedImage img = ImageIO.read(f);
int[] ib = img.getRGB(0, 0, img.getWidth(), img.getHeight(), null, 0, img.getWidth());
Color c = new Color(ib[0]);
System.out.println(c.getRed() + " " + c.getGreen() + " " + c.getBlue());
Run Code Online (Sandbox Code Playgroud)

但是在这里我得到了这个输出:255 128 128由于我清楚地看到(并且已经在几个图像编辑器中验证过)(0,0)处的像素具有这些值,所以这是预期的255 255 255.

我注意到返回的类型img.getType()等于TYPE_3BYTE_BGR所以我猜这是在场景后面发生的解码问题,但我无法弄清楚如何解决它(或者更清楚地了解正在发生的事情).

有没有人会对如何正确解码这种类型提出建议?

java rgb jpeg image image-processing

5
推荐指数
1
解决办法
6289
查看次数

如何移动JPanel

我有一个JDialog包含JPanel和其他元素JTextField.我想JDialog在屏幕上加载后从一个位置移动到另一个位置.当我尝试使用时jdialog.setLocation(),我无法移动,JDialog并且添加到其中的所有其他组件也变得不可见.

谁能告诉我我的方法可能有什么问题?

java swing awt

5
推荐指数
1
解决办法
8895
查看次数