Hallo,
ich stehe vor folgendem Problem. Ich habe mir mit SWT eine view erstellt und diese zeigt nun per GridLayout einen String, darunter eine Sprechblase und darunter ein Strichmännchen an. Soweit so gut. Nun soll die Sprechblase nicht leer sein, sondern logischerweise mit Text gefüllt werden, der aber dynamisch ist und keine feste Länge hat, dies hab ich mit GC.drwaString() vorgenommen. Problem: Wenn ich den String dann um einige Wörter ergänze, wird kein automatischer Zeilenumbruch vorgenommen, sondern einfach alles in einer Zeile geschrieben bzw. nur soviel Text angezeigt, wie in eine Zeile des Labels passt. Frage: Gibt es eine art autosize Methode oder ähnliches?
private void createCallInput(String convName, Conversation conv) {
// TODO get entries if only 1 entry put picture and get send voice output
comp.setLayout(new GridLayout(1, true));
Label lab = new Label(comp, SWT.NONE);
lab.setText(convName);
lab.setFont(new Font(comp.getDisplay(), "Arial", 40, SWT.COLOR_BLACK));
data = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 0);
data.horizontalIndent = lab.getLocation().x + 45;
lab.setLayoutData(data);
String text = viewAdapter.getSendVoiceInputContent(conv);
Label label = new Label(comp, SWT.TRANSPARENT);
Image image = new Image(comp.getDisplay(), getClass().getResourceAsStream("/icons/speechbubble.png"));
int width = image.getBounds().width;
int height = image.getBounds().height;
Image speechBubble = new Image(comp.getDisplay(), image.getImageData().scaledTo((int) (width * 2),
(int) (height * 1.1)));
label.setImage(speechBubble);
label.setFont(new Font(comp.getDisplay(), "Arial", 28, SWT.COLOR_BLACK));
data = new GridData(SWT.CENTER, SWT.CENTER, true, true);
GC gc = new GC(speechBubble);
gc.setAntialias(SWT.ON);
gc.setBackground(new Color(comp.getDisplay(), 130, 172, 26));
gc.setFont(new Font(comp.getDisplay(), "Arial", 20, SWT.COLOR_BLACK));
gc.drawString(text, speechBubble.getBounds().x + 10, speechBubble.getBounds().y + 10);
label.setLayoutData(data);
Label person = new Label(comp, SWT.NONE);
Image pers = new Image(comp.getDisplay(), getClass().getResourceAsStream("/icons/menschSymbol.png"));
width = pers.getBounds().width;
height = pers.getBounds().height;
Image personImage = new Image(comp.getDisplay(), pers.getImageData().scaledTo((int) (width * 0.08),
(int) (height * 0.08)));
person.setImage(personImage);
data = new GridData(SWT.CENTER, SWT.CENTER, true, true, 1, 0);
data.horizontalIndent = person.getLocation().x - 230;
data.verticalIndent = person.getLocation().y - 40;
person.setLayoutData(data);
comp.layout();
}
Danke im Voraus
ich stehe vor folgendem Problem. Ich habe mir mit SWT eine view erstellt und diese zeigt nun per GridLayout einen String, darunter eine Sprechblase und darunter ein Strichmännchen an. Soweit so gut. Nun soll die Sprechblase nicht leer sein, sondern logischerweise mit Text gefüllt werden, der aber dynamisch ist und keine feste Länge hat, dies hab ich mit GC.drwaString() vorgenommen. Problem: Wenn ich den String dann um einige Wörter ergänze, wird kein automatischer Zeilenumbruch vorgenommen, sondern einfach alles in einer Zeile geschrieben bzw. nur soviel Text angezeigt, wie in eine Zeile des Labels passt. Frage: Gibt es eine art autosize Methode oder ähnliches?
private void createCallInput(String convName, Conversation conv) {
// TODO get entries if only 1 entry put picture and get send voice output
comp.setLayout(new GridLayout(1, true));
Label lab = new Label(comp, SWT.NONE);
lab.setText(convName);
lab.setFont(new Font(comp.getDisplay(), "Arial", 40, SWT.COLOR_BLACK));
data = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 0);
data.horizontalIndent = lab.getLocation().x + 45;
lab.setLayoutData(data);
String text = viewAdapter.getSendVoiceInputContent(conv);
Label label = new Label(comp, SWT.TRANSPARENT);
Image image = new Image(comp.getDisplay(), getClass().getResourceAsStream("/icons/speechbubble.png"));
int width = image.getBounds().width;
int height = image.getBounds().height;
Image speechBubble = new Image(comp.getDisplay(), image.getImageData().scaledTo((int) (width * 2),
(int) (height * 1.1)));
label.setImage(speechBubble);
label.setFont(new Font(comp.getDisplay(), "Arial", 28, SWT.COLOR_BLACK));
data = new GridData(SWT.CENTER, SWT.CENTER, true, true);
GC gc = new GC(speechBubble);
gc.setAntialias(SWT.ON);
gc.setBackground(new Color(comp.getDisplay(), 130, 172, 26));
gc.setFont(new Font(comp.getDisplay(), "Arial", 20, SWT.COLOR_BLACK));
gc.drawString(text, speechBubble.getBounds().x + 10, speechBubble.getBounds().y + 10);
label.setLayoutData(data);
Label person = new Label(comp, SWT.NONE);
Image pers = new Image(comp.getDisplay(), getClass().getResourceAsStream("/icons/menschSymbol.png"));
width = pers.getBounds().width;
height = pers.getBounds().height;
Image personImage = new Image(comp.getDisplay(), pers.getImageData().scaledTo((int) (width * 0.08),
(int) (height * 0.08)));
person.setImage(personImage);
data = new GridData(SWT.CENTER, SWT.CENTER, true, true, 1, 0);
data.horizontalIndent = person.getLocation().x - 230;
data.verticalIndent = person.getLocation().y - 40;
person.setLayoutData(data);
comp.layout();
}
Danke im Voraus