문제
JOptionPane 메시지 대화 상자를 사용하고 있다면 메시지 섹션에 이 작은 조각과 같은 전체 배열을 어떻게 표시할 수 있습니까?아니면 그게 가능할까요?
public void showTheMessage()
{
JOptionPane.showMessageDialog(null,"These are are all the colors to
choosfrom,\n"+ arrayOfcolors[the whole array], "Color box");
}
해결책
가장 쉬운 방법은 배열의 모든 요소를 하나의 큰 문자열로 연결하는 것입니다.
String colors = "";
for(int i = 0; i < arrayOfColors.length; i++)
colors += arrayOfColors[i] + " ";
다른 팁
그만큼 showoptionDialog 메소드 사용자가 다양한 옵션에서 단일 요소를 선택할 수 있습니다.
색상 객체의 배열 인 경우
String colors="";
for (Color c: arrayOfColors)
colors+= c.toString() + " ";
그렇지 않으면 문자열 객체의 배열 인 경우
String colors="";
for (String s: arrayOfColors)
colors+= s + " ";
StringBuilder를 사용하는 것이 훨씬 빠르지 만 이것은 단지 작은 배열 일뿐입니다.
제휴하지 않습니다 StackOverflow