小编ham*_*314的帖子

当我在Apache PDFBox 2.x中使用moveTo/lineTo/stroke的版本切换不推荐的drawLine()方法时,为什么我的线条会消失?

我通过这个例子创建了一个表:http://fahdshariff.blogspot.de/2010/10/creating-tables-with-pdfbox.html

现在我已经从Apache PDFBox 1.8切换到2.0,因此现在不推荐使用某些方法,包括drawLine()-method.

API变更规定,你必须使用的其他3种方法相结合现在完成画线的任务:

org.apache.pdfbox.pdmodel.PDPageContentStream.drawLine(float, float, float, float):
Use PDPageContentStream.moveTo(float, float) 
followed by PDPageContentStream.lineTo(float, float) 
followed by PDPageContentStream.stroke()
Run Code Online (Sandbox Code Playgroud)

因此我改变了这一行

final float tableWidth = page.findMediaBox().getWidth() - (2 * margin);
Run Code Online (Sandbox Code Playgroud)

到这一行:

final float tableWidth = page.getMediaBox().getWidth() - (2 * margin);
Run Code Online (Sandbox Code Playgroud)

并改变这两行

// draw the rows
contentStream.drawLine(margin, nexty, margin + tableWidth, nexty);
(...)
// draw the columns
contentStream.drawLine(nextx, y, nextx, y - tableHeight);
Run Code Online (Sandbox Code Playgroud)

对此:

// draw the rows
contentStream.moveTo(margin, nexty);
contentStream.lineTo(margin, nexty);
contentStream.stroke();
(...)
// …
Run Code Online (Sandbox Code Playgroud)

java pdfbox

4
推荐指数
1
解决办法
1968
查看次数

为什么在ArrayList上使用for-each循环不起作用?

偶然发现了这个代码,它抛出了一个ConcurrentModificationException

ArrayList<String> list = new ArrayList<String>(Arrays.asList("a", "b", "c", "d"));

for (String s : list) {
    if (s.equals("a"))
        list.remove(s);
}
Run Code Online (Sandbox Code Playgroud)

如果你添加一个迭代器并使用while循环,代码工作正常:

ArrayList<String> list = new ArrayList<String>(Arrays.asList("a", "b", "c", "d"));
Iterator<String> iter = list.iterator();
while (iter.hasNext()) {
    String s = iter.next();

    if (s.equals("a")) {
        iter.remove();
    }
}
Run Code Online (Sandbox Code Playgroud)

我不明白,为什么有必要Iterator<String>在这种情况下使用.是因为ArrayList没有某种迭代能力,尽管它是Collection子类

是否有必要使用while循环,或者您是否可以生成带有for循环的版本?

java exception arraylist

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

这个map/string数组中发生了什么?

首先,我的代码工作正常.没有什么需要做的,但是当我从其他地方复制代码的某些部分时,我不完全理解这里发生的事情并希望得到解释来学习一些东西.

我使用play框架并向我的控制器类发送一个带有ID和分数的AJAX POST.我将这些参数放入字符串并将其保存在我的数据库中.

Map<String, String[]> parameters = request().body().asFormUrlEncoded();
        String questionIDInput = parameters.get("questionID")[0];
        String voteScoreInput = parameters.get("score")[0];
Run Code Online (Sandbox Code Playgroud)

我得到的部分是:.get("questionID")[0]; / .get("score")[0];.为什么那里有两个零?地图是某种长字符串,我"questionID / score"用作查找值的键吗?0真的让我感到困惑,请赐教.

java arrays string dictionary

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

如何在play框架的表单助手中隐藏标签?

我有一个表单,用户可以在其中输入问题.每个字段都有一个标签,但在生产环境中我不想显示标签和某些inputText字段.我试图通过使用'style -> "display: none"删除inputText字段而不是标签来摆脱它们.我在play框架网站上没有找到解释:https://www.playframework.com/documentation/2.0.4/JavaFormHelpers

有没有办法通过内置工具实现这一目标,还是有其他可能性?

@import helper._
@import helper.twitterBootstrap._

@helper.form(action = routes.Application.sendQuestion()){
        <fieldset>
            @helper.inputText(questionForm("questionID"),'style -> "display: none")
            @helper.inputText(questionForm("questionText"))
            @helper.inputText(questionForm("voteScore"))
            @helper.inputText(questionForm("ownerID"))
            @helper.inputText(questionForm("page"))
        </fieldset>
        <input type="submit" class="btn btn-default">
    }
Run Code Online (Sandbox Code Playgroud)

java forms playframework

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

为什么我的变量equipmentNumber不能到达?

我有一个5页的应用程序.

在第一页(AdressPanel)上,您将一些信息(如equipmentNumber)输入到文本字段中.然后单击按钮以更新其他页面并转到下一页(LiftDataRevisionDocumentsPanel).在JLabel上应该显示您在第1页上输入的值.

但无论我做什么,它都不会显示输入的值.

我尝试了几个关键字equipmentNumber:static, final, public, private但没有任何变化.当我使用final时,我收到错误消息the final field ... cannot be assigned.

请注意:我没有在我的示例代码中使用前面提到的文本字段,而是尝试将字符串"1234567890" equipmentNumber直接放入.两种方式都不起作用,请参阅ActionListener.

那么为什么我无法到达变量equipmentNumber/更改第二页上的标签?

public class TestApplication {
    static String equipmentNumber;

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    TestApplication window = new TestApplication();
                    window.frmTool.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    public TestApplication() {
        initialize();
    }

    private void initialize() {
        frmTool = …
Run Code Online (Sandbox Code Playgroud)

java swing actionlistener

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

当我的其他人应该阻止它时,为什么我会得到IndexOutOfBoundsException?

我正在进行某种测验,并有一个问题和答案列表,通过控制器转移到我的视图类.人们可以在一个页面上提问和回答问题,然后我的系统会"收集"这些问题以便从中进行测验.

如果您是第一个启动程序/测验的人,则问题列表为空.因此,我想检查一个带有if/else子句的空测验,if-case似乎工作正常,但是else-case抛出一个IndexOutOfBoundsException而我不明白为什么.我认为当问题列表为空时不会使用else-part,因此不应该抛出异常.应该....

查看课程:

@(questionList: List[Question], answerList: List[Answer], answerRadioForm: Form[Answer])

@if(questionList.length == 0){
    No questions yet!
}

else {
<!-- As only the highest ranked question gets put into the List, there is only one entry on first place -->
<b>@questionList.get(0).questionText</b>

    @for(question <- questionList)  {
        @question.questionText - @question.ownerID <br>
    }
} 
Run Code Online (Sandbox Code Playgroud)

错误:

[IndexOutOfBoundsException: Index: 0, Size: 0]
49          <b>"""),_display_(/*27.8*/questionList/*27.20*/.get(0).questionText),format.raw/*27.40*/("""</b>
Run Code Online (Sandbox Code Playgroud)

那么,我在这里错过了什么?

scala exception playframework

0
推荐指数
1
解决办法
173
查看次数