Ich bin neu in Java, ich würde gerne wissen, wie bekomme ich meine Textarea aus der Hauptklasse?Holen Sie sich eine Textarea in Java mit JFrame
Dies ist mein Code:
public static void main(String[] args) {
UIManager.put("swing.boldMetal", Boolean.FALSE);
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
private static void createAndShowGUI() {
frame = new JFrame("Frame");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GuiManager animator = new GuiManager();
frame.add(animator, BorderLayout.CENTER);
// Display the window.
frame.pack();
frame.setSize(800, 500);
frame.setVisible(true);
}
und GuiManager:
public GuiManager() {
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
// .............
// Create Scrolling Text Area in Swing
JPanel panelLabel = new JPanel();
panelLabel.setLayout(new FlowLayout()); // No content pane for JPanel.
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout()); // No content pane for JPanel.
JLabel ta1Label = new JLabel("Label One", JLabel.LEFT);
ta1Label.setAlignmentX(Component.LEFT_ALIGNMENT);
JTextArea ta = new JTextArea("", 10, 30);
ta.setLineWrap(true);
JScrollPane sbrText = new JScrollPane(ta);
sbrText.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
JLabel ta2Label = new JLabel("Label2", JLabel.RIGHT);
ta2Label.setAlignmentX(Component.RIGHT_ALIGNMENT);
JTextArea ta2 = new JTextArea("", 10, 30);
ta2.setLineWrap(true);
JScrollPane sbrText2 = new JScrollPane(ta2);
sbrText2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
panelLabel.add(ta1Label);
panelLabel.add(ta2Label);
panel.add(sbrText);
panel.add(sbrText2);
// Put everything together.
add(panelLabel);
add(panel);
setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
}
Mein Ziel ist es, die Ausgabe zu diesem Textbereich, und für einige Ausgabe ich auf dem zu dem Text umleiten muß umleiten links, aber irgendwann muss ich auf dem Textfeld auf der rechten Seite ausgeben. Was wäre die beste Lösung dafür? Vielen Dank.
Ihre Frage ist weder klar noch prägnant – ControlAltDel