2016-09-02 2 views
-2

내 보고서의 모든 음수가 빨간색이어야합니다. 숫자 서식을 통해이 작업을 수행 할 수있는 방법이 있습니까? 그렇지 않다면 현재 텍스트 필드를 확인하는 어딘가에 동적 조건을 만들 수 있습니까? 예를 들어JasperSoft Studio의 동적으로 빨간색 음수

는 :

If this Textfield < 0 then this texfield font is red 

가 명심

, 내가 조건을 변경하지 않고 모든 텍스트 필드에 드롭 할 수있는 의미에서 동적해야합니다.

조건에 맞는 특정 필드를 사용하는 대신 조건부 스타일을 이해합니다 (중복 된 것으로 표시된 질문에서와 같이). 조건을 텍스트 필드로 끌어 와서 0보다 작지 않습니다.

고마워요!

+2

[JasperReports의 조건에 따라 텍스트 필드 데이터 색상 (전경색) 변경] (http://stackoverflow.com/questions/8754448/change-text-field-data-color-foreground-color-based- 온 컨디션 인 재스 페레포) –

+0

네, 조건부 스타일을 이해하지만 특정 필드를 사용하는 것보다는 그 예제에서이 조건을 많은 다른 텍스트 필드로 드래그 할 수있는 감각을보다 동적으로하고 싶습니다. 이 질문은 다른 질문과 조금 더 복잡합니다. – Matt

답변

0

조건부 스타일로는이를 수행 할 수 없습니다.

이 솔루션과 같이 markup="styled"로 구성된 텍스트 필드 출력 텍스트 스타일 것이다 사용자 정의 포매터를 만들고이하는 것입니다 :

<textField> 
    <reportElement x="72" y="16" width="100" height="24" uuid="698866c8-7d26-4bc7-8727-b4a56d239a53"/> 
    <textElement markup="styled"/> 
    <textFieldExpression><![CDATA[NegativeNumberFormatter.format($F{A1}, "#,##0.###")]]></textFieldExpression> 
</textField> 

NegativeNumberFormatter은 (기본 패키지를 사용) 다음과 같습니다

import java.text.DecimalFormat; 

public class NegativeNumberFormatter { 

    public static String format(Number n, String pattern) { 
    if (n != null) { 
     if (n.doubleValue() < 0) { 
     DecimalFormat df = new DecimalFormat(); 

     if (pattern != null) { 
      df.applyPattern(pattern); 
     } 

     return "<font color=\"red\">" + df.format(n) + "</font>"; 
     } else { 
     return "" + n; 
     } 
    } 

    return null; 
    } 
} 
관련 문제