ERLEDIGT
NEIN
NEIN
ANTWORTEN
0
0
ZUGRIFFE
577
577
EMPFEHLEN
-
Hallo,
wir wollen in einem boxlayout mehrere jtextpanes in ein jpanel einfügen. Diese jtextpanes sollen
html enthalten und einen automatischen Zeilenumbruch am Zeilenende ausführen.
Außerdem sollen nach und nach neue jtextpanes in das jlabel integriert werden.
Unser Problem liegt nun darin, dass bei längeren Texten der Zeilenumbruch zwar stattfindet, aber plötzlich rechts und links zwei graue Bereiche entstehen und nur in der Mitte der formatierte Text steht. Wie kriegen wir die grauen Balken weg, sodass der Text ganz normal auf der linken Seite angezeigt wird?

Wisst ihr irgendeine Lösung?
Hier ist der Code dazu:
Code java:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import javax.swing.BoxLayout; import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.JTextPane; import javax.swing.LayoutStyle; import javax.swing.ScrollPaneConstants; import javax.swing.SwingUtilities; public class Test extends JFrame { private static final long serialVersionUID = -2165717127504007034L; private JButton add; private JTextField input; private JPanel outputPane; private JScrollPane scrollPane; public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { Test test = new Test(); test.setLocationRelativeTo(null); test.setVisible(true); } }); } public Test() { this.initGUI(); } public void appendToOutput() { String msg = "<html><body><p style=\"margin-top:10px\"; align=\"left\"> <font size=\"3\" face=\"arial\" color=\"red\">" + this.input.getText() + "</p></body></html>"; this.input.setText(""); this.input.requestFocus(); JTextPane out = new JTextPane(); out.setMaximumSize(new Dimension(379, 200)); out.setContentType("text/html"); out.setEditable(false); out.setText(msg); this.outputPane.add(out); this.outputPane.updateUI(); } private void initGUI() { try { GroupLayout thisLayout = new GroupLayout(this.getContentPane()); this.getContentPane().setLayout(thisLayout); { this.outputPane = new JPanel(); BoxLayout outputPaneLayout = new BoxLayout(this.outputPane, javax.swing.BoxLayout.Y_AXIS); this.outputPane.setLayout(outputPaneLayout); this.outputPane.setMaximumSize(new Dimension(379, 32767)); this.outputPane.setAutoscrolls(true); { this.scrollPane = new JScrollPane(this.outputPane); this.scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); this.scrollPane.setMaximumSize(new java.awt.Dimension(379, 32767)); } } { this.add = new JButton(); this.add.setText("add"); this.add.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Test.this.appendToOutput(); } }); this.add.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent event) { if ((event.getKeyCode() == KeyEvent.VK_ENTER)) { Test.this.appendToOutput(); } } }); } { this.input = new JTextField(); this.input.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent event) { if ((event.getKeyCode() == KeyEvent.VK_ENTER)) { Test.this.appendToOutput(); } } }); } thisLayout.setVerticalGroup(thisLayout .createSequentialGroup() .addComponent(this.scrollPane, GroupLayout.PREFERRED_SIZE, 213, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup( thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(this.add, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(this.input, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)) .addContainerGap(20, 20)); thisLayout.setHorizontalGroup(thisLayout .createParallelGroup() .addComponent(this.scrollPane, GroupLayout.Alignment.LEADING, 0, 394, Short.MAX_VALUE) .addGroup( GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup().addGap(7).addComponent(this.input, GroupLayout.PREFERRED_SIZE, 253, GroupLayout.PREFERRED_SIZE).addGap(27) .addComponent(this.add, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE).addContainerGap(37, Short.MAX_VALUE))); { this.setSize(400, 300); this.setResizable(false); this.pack(); } } catch (Exception e) { e.printStackTrace(); } } }
Ähnliche Themen
-
ScrollPane auf einem JPanel
Von nathaniells freak im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 3Letzter Beitrag: 13.03.09, 09:15 -
Mit Jogl auf einem JPanel zeichen
Von Hausgeist im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 1Letzter Beitrag: 18.09.08, 15:30 -
Ein Bild in mehrere JPanel einfügen...
Von mp89 im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 2Letzter Beitrag: 23.07.07, 21:47 -
Eine art StateChange bei einem JPanel
Von elmato im Forum JavaAntworten: 4Letzter Beitrag: 25.10.06, 14:15 -
Mehrere JPanel übereinander und gleichzeitig klickbar
Von bocee83 im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 1Letzter Beitrag: 28.08.05, 15:41





Zitieren
Login





