이 질문은 Java Swing: Vertical Layout with fixed width and variable height으로, Apache Pivot을 시도 할 수있는 기회가되었습니다. 정확히 하루 피벗의 경험이 있습니다.Apache Pivot GUI 구성 요소의 크기 조정
다음은 내가 만들었던 GUI입니다. Expander
, ScrollPane
및 TextArea
윈도우의 폭을 채우도록
가 어떻게의
Expander
의 일부 년대TextArea
크기를 않으며, :내 질문 은
TextArea
은 임의의 양의 텍스트를 저장할 수있을 정도로 키가 큽니까? 확장 된 텍스트 영역의 모든 3Expander
의 윈도우의 높이에 맞게 때은 어떻게
Expander
의ScrollPane
의 높이도록 크기를합니까?
다음은 GUI를 생성 한 소스 코드입니다. Apache Pivot 버전 2.0.2를 사용하고 있습니다.
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.pivot.collections.Map;
import org.apache.pivot.wtk.Application;
import org.apache.pivot.wtk.BoxPane;
import org.apache.pivot.wtk.DesktopApplicationContext;
import org.apache.pivot.wtk.Display;
import org.apache.pivot.wtk.Expander;
import org.apache.pivot.wtk.Orientation;
import org.apache.pivot.wtk.ScrollPane;
import org.apache.pivot.wtk.TextArea;
import org.apache.pivot.wtk.Window;
public class Segments implements Application {
protected SectionCollection collection;
protected Window window;
@Override
public void startup(Display display, Map<String, String> properties) {
collection = new SectionCollection();
new SectionCollectionCreator(collection);
window = new Window();
window.setTitle("Segments");
window.setMaximized(true);
BoxPane boxPane = new BoxPane();
boxPane.setOrientation(Orientation.VERTICAL);
for (int i = 0; i < collection.size(); i++) {
SectionText sectionText = collection.get(i);
TextArea textArea = new TextArea();
textArea.setEditable(false);
textArea.setPreferredSize(400, 220);
try {
textArea.setText(sectionText.getTopic());
} catch (IOException e) {
e.printStackTrace();
}
ScrollPane textScrollPane = new ScrollPane();
textScrollPane.setPreferredSize(420, 100);
textScrollPane.setVerticalScrollBarPolicy(
ScrollPane.ScrollBarPolicy.AUTO);
textScrollPane.setView(textArea);
Expander expander = new Expander();
expander.setTitle(sectionText.getTitle());
expander.setContent(textScrollPane);
expander.setExpanded(false);
boxPane.add(expander);
}
ScrollPane expanderScrollPane = new ScrollPane();
expanderScrollPane.setHorizontalScrollBarPolicy(
ScrollPane.ScrollBarPolicy.AUTO);
expanderScrollPane.setVerticalScrollBarPolicy(
ScrollPane.ScrollBarPolicy.AUTO);
expanderScrollPane.setView(boxPane);
window.setContent(expanderScrollPane);
window.open(display);
}
@Override
public boolean shutdown(boolean optional) {
if (window != null) {
window.close();
}
return false;
}
@Override
public void suspend() {
}
@Override
public void resume() {
}
public static void main(String[] args) {
DesktopApplicationContext.main(Segments.class, args);
}
public class SectionText {
protected String title;
protected Reader topic;
public SectionText(String title, Reader topic) {
this.title = title;
this.topic = topic;
}
public String getTitle() {
return title;
}
public Reader getTopic() {
return topic;
}
}
public class SectionCollection {
protected List<SectionText> collection;
public SectionCollection() {
this.collection = new ArrayList<SectionText>();
}
public void add(SectionText sectionText) {
collection.add(sectionText);
}
public int size() {
return collection.size();
}
public SectionText get(int index) {
return collection.get(index);
}
}
public class SectionCollectionCreator {
protected SectionCollection collection;
protected static final String text = "Attributes, Styles and Style Contexts\n\n"
+ "The simple PlainDocument class that you saw in the previous "
+ "chapter is only capable of holding text. The more complex text "
+ "components use a more sophisticated model that implements the "
+ "StyledDocument interface. StyledDocument is a sub-interface of "
+ "Document that contains methods for manipulating attributes that "
+ "control the way in which the text in the document is displayed. "
+ "The Swing text package contains a concrete implementation of "
+ "StyledDocument called DefaultStyledDocument that is used as the "
+ "default model for JTextPane and is also the base class from which "
+ "more specific models, such as the HTMLDocument class that handles "
+ "input in HTML format, can be created. In order to make use of "
+ "DefaultStyledDocument and JTextPane, you need to understand how "
+ "Swing represents and uses attributes.";
public SectionCollectionCreator(SectionCollection collection) {
this.collection = collection;
String title = "Title ";
for (int i = 1; i <= 3; i++) {
SectionText sectionText = new SectionText(title + i,
new StringReader(text));
collection.add(sectionText);
}
}
}
}
감사합니다. 나는 아직도 Pivot을 배우고있다. –