-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.1.6, 1.2.0
-
generic, x86, sparc
-
generic, solaris_2.5.1, windows_nt
Name: rk38400 Date: 05/15/98
Why is there no border around a JTextArea in Windows and Motif L&F when
there is a border around JTextFields?
Is it a bug or intentional?
Metal L&F has borders on both.
Code example:
class Windows extends WindowsLookAndFeel
{
public boolean isSupportedLookAndFeel()
{
return true;
}
}
public class bug9
{
public static void main (String argv[]) throws ClassNotFoundException, InstantiationException, IllegalAccessException,
UnsupportedLookAndFeelException
{
JFrame frame = new JFrame("Bug");
// Comment and uncomment to select L&F
UIManager.setLookAndFeel(new Windows());
//UIManager.setLookAndFeel(new com.sun.java.swing.plaf.motif.MotifLookAndFeel());
//UIManager.setLookAndFeel(new com.sun.java.swing.plaf.metal.MetalLookAndFeel());
// Get the top level container
Container contentPane = frame.getContentPane();
contentPane.setLayout(new BorderLayout());
JTextArea textarea = new JTextArea("Area");
JTextField textfield = new JTextField("Field");
contentPane.add(textarea, "North");
contentPane.add(textfield, "South");
frame.setSize(200,200);
frame.show();
}
}
(Review ID: 30369)
======================================================================
erik.larsen@Eng 1998-05-29
Compile these two classes and run "java Test".
None of the JTextFields have borders except
the one where it is set explicitly.
Test.java----------------------------
import com.sun.java.swing.*;
public class Test
{
public Test()
{
String lf = UIManager.getSystemLookAndFeelClassName();
if ( lf != null )
{
try
{
UIManager.setLookAndFeel( "com.sun.java.swing.plaf.motif.MotifLookAn
dFeel" );
}
catch ( Exception ex )
{
ex.printStackTrace();
}
}
MyFrame mf = new MyFrame();
mf.setSize( 400, 200 );
mf.show();
}
public static void main( String args[] )
{
new Test();
}
}
MyFrame.java-------------------------------
import com.sun.java.swing.*;
import com.sun.java.swing.border.*;
import com.sun.java.swing.text.*;
import com.sun.java.swing.event.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
public class MyFrame extends JFrame implements
DocumentListener
{
JPanel mPanel;
public MyFrame()
{
setTitle( "JTextField1" );
// Store the content pane in a variable for easier
// access.
mPanel = (JPanel)getContentPane();
// Components will all be added to this panel.
mPanel.setLayout( new BoxLayout( mPanel,
BoxLayout.Y_AXIS ) );
// Leave empty space around the edge of the content
// pane.
mPanel.setBorder( new EmptyBorder( 10, 10, 10, 10 ) );
// The first label/text field combination.
{
Box pane = Box.createHorizontalBox();
JLabel lbl =
new JLabel( "Set text in constructor: " );
pane.add( lbl );
// Create the JTextField, specifying text in the
// constructor.
JTextField t1 =
new JTextField( "Put in by constructor" );
// Add the text field to the box.
pane.add( t1 );
// Add the box to the content pane, and pad
// between it and the next.
mPanel.add( pane );
mPanel.add( Box.createVerticalGlue() );
}
// The second label/text field combination.
{
Box pane = Box.createHorizontalBox();
JLabel lbl =
new JLabel( "Set text with setText(): " );
pane.add( lbl );
// Create an empty text field.
JTextField t1 = new JTextField();
// Set the text field's contents.
t1.setText( "Here is text" );
// Add the text field to the box.
pane.add( t1 );
// Add the box to the content pane and leave some
// space between it and the next.
mPanel.add( pane );
mPanel.add( Box.createVerticalGlue() );
}
// The third label/text field combination.
{
Box pane = Box.createHorizontalBox();
JLabel lbl =
new JLabel( "Changed font and colors: " );
pane.add( lbl );
// Create the text field and give it some text.
JTextField t1 = new JTextField(
"See the font and color changes" );
// Set the font.
t1.setFont( new Font( "TimesRoman",
Font.ITALIC, 18 ) );
// Set the text color.
t1.setForeground( Color.red );
// Set the background color.
t1.setBackground( Color.green );
// Add the text field to the box.
pane.add( t1 );
// Add the box to the content pane and leave some
// space.
mPanel.add( pane );
mPanel.add( Box.createVerticalGlue() );
}
// The fourth label/text field combination.
{
Box pane = Box.createHorizontalBox();
JLabel lbl =
new JLabel( "Ctrl-C cuts selection: " );
pane.add( lbl );
// Create a text field and give it some text.
JTextField t1 = new JTextField(
"Select text and press Ctrl-C" );
// Get the text field's keymap.
Keymap map = t1.getKeymap();
// Get the Ctrl-C keystroke.
KeyStroke cut = KeyStroke.getKeyStroke(
KeyEvent.VK_C,
ActionEvent.CTRL_MASK, false );
// Create an instance of the action that will cut
// selected text.
CutAction cutAction = new CutAction();
// Put the keystroke/action pair into the keymap.
map.addActionForKeyStroke( cut, cutAction );
// Put the keymap back in the text field.
t1.setKeymap( map );
// Add the text field to the box.
pane.add( t1 );
// Add the box to the content pane and leave some
// space.
mPanel.add( pane );
mPanel.add( Box.createVerticalGlue() );
}
// The fifth label/text field combination.
{
Box pane = Box.createHorizontalBox();
JLabel lbl = new JLabel( "Changed border: " );
pane.add( lbl );
// Create a text field and give it some text.
JTextField t1 = new JTextField(
"See the border change" );
// Change the border.
t1.setBorder( new BevelBorder(
BevelBorder.RAISED ) );
// Add the text field to the box.
pane.add( t1 );
// Add the box to the content pane and leave some
// space.
mPanel.add( pane );
mPanel.add( Box.createVerticalGlue() );
}
// The sixth label/text field combination.
{
Box pane = Box.createHorizontalBox();
JLabel lbl =
new JLabel( "Tracking DocumentEvents: " );
pane.add( lbl );
// Create a text field and give it some text.
JTextField t1 = new JTextField(
"Type or delete to generate DocumentEvents" );
// Make it so this class is notified when text is
// inserted into or removed from the text field.
t1.getDocument().addDocumentListener( this );
// Add the text field to the box.
pane.add( t1 );
// Add the box to the content pane.
mPanel.add( pane );
}
}
// This is called when attributes change in the document.
// This won't generally happen in a PlainDocument.
public void changedUpdate( DocumentEvent e )
{
System.out.println( "Changed: " + e );
}
// This is called when text is inserted into a document.
public void insertUpdate( DocumentEvent e )
{
System.out.println( "Inserted" );
}
// This is called when text is deleted from a document.
public void removeUpdate( DocumentEvent e )
{
System.out.println( "Removed" );
}
// This action cuts the selected text (if any) from a
// JTextField.
private class CutAction extends AbstractAction
{
public void actionPerformed(ActionEvent e)
{
JTextField tf = (JTextField)e.getSource();
tf.cut();
}
}
}
- duplicates
-
JDK-4154670 JTextArea does not have a border, but JTextField does.
-
- Closed
-