K
Kevin Munro
Hello, I'm writing a java app for a pda and as the screen size is tiny I
want to write a MiniDialog class. I only want a JTextArea and an OK button
on it and I want the JTextArea to fit the size of the modal dialog.
If I pass in a long line of text then the JTextArea appears to get wider and
I have to scroll across the screen to see the text. I want it to wrap onto
the second line etc.
I must be doing something stupid!
Thanks, Kevin.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MiniDialog {
JDialog dialog=new JDialog(new JFrame(),"Info",true);
public MiniDialog() { }
public void show(String label) {
Container c=dialog.getContentPane();
JButton ok=new JButton("OK");
dialog.getRootPane().setDefaultButton(ok);
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.dispose();
}
});
JTextArea txt=new JTextArea(5,20);
txt.setEditable(false);
txt.append(label);
JScrollPane scroll=new JScrollPane(txt);
scroll.setSize(1,1);
dialog.setSize(200,200);
dialog.setLocation(20,40);
c.add(scroll,BorderLayout.CENTER);
c.add(ok,BorderLayout.SOUTH);
dialog.show();
}
}
want to write a MiniDialog class. I only want a JTextArea and an OK button
on it and I want the JTextArea to fit the size of the modal dialog.
If I pass in a long line of text then the JTextArea appears to get wider and
I have to scroll across the screen to see the text. I want it to wrap onto
the second line etc.
I must be doing something stupid!
Thanks, Kevin.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MiniDialog {
JDialog dialog=new JDialog(new JFrame(),"Info",true);
public MiniDialog() { }
public void show(String label) {
Container c=dialog.getContentPane();
JButton ok=new JButton("OK");
dialog.getRootPane().setDefaultButton(ok);
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.dispose();
}
});
JTextArea txt=new JTextArea(5,20);
txt.setEditable(false);
txt.append(label);
JScrollPane scroll=new JScrollPane(txt);
scroll.setSize(1,1);
dialog.setSize(200,200);
dialog.setLocation(20,40);
c.add(scroll,BorderLayout.CENTER);
c.add(ok,BorderLayout.SOUTH);
dialog.show();
}
}