-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.4.0
-
x86
-
windows_2000
Name: jk109818 Date: 01/15/2003
FULL PRODUCT VERSION :
java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
When the JTextfield(int cols) constructor is used to
instantiate a JTextfield and it's placed on an JApplet, the
JTextfield does not have any width (Probably it's just 1
pixel wide).
The problem could be with the JApplet/GridBagLayout and is
percieved in this usage of JTextField.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile the AccTestFrame code below
2. Run AccTestFrame
3. Compile the AccTestApplet code below
4. Run AccTestApplet. Using browser or appletviewer.
EXPECTED VERSUS ACTUAL BEHAVIOR :
The AccTestApplet shows the textfields with no width
The AccTestFrame shows the textfields appropriately
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
-----------AccTestFrame-----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class AccTestFrame {
public static void main (String[] args){
JFrame frame = new JFrame();
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
Container container = frame.getContentPane();
container.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0; gbc.gridy = 0;
gbc.insets = new Insets(2, 5, 2, 5);
gbc.anchor = GridBagConstraints.WEST;
gbc.gridy = 0; gbc.gridx = 0;
gbc.gridwidth = 1;
container.add(new JLabel("Name:"), gbc);
gbc.gridx += 2;
// gbc.gridwidth = GridBagConstraints.REMAINDER;
container.add(new JTextField(40), gbc);
gbc.gridy++;
gbc.gridwidth = 2;
gbc.gridx = 0;
container.add(new JLabel("Address:"), gbc);
gbc.gridx += 2;
// gbc.gridwidth = GridBagConstraints.REMAINDER;
container.add(new JTextField(40), gbc);
frame.pack();
frame.setVisible(true);
} // main
} //AccTestFrame
-----------AccTestFrame-----------
-----------AccTestApplet-----------
import java.awt.*;
import javax.swing.*;
public class AccTestApplet extends JApplet {
public void init() {
Container container = getContentPane() ;
container.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0; gbc.gridy = 0;
gbc.insets = new Insets(2, 5, 2, 5);
gbc.anchor = GridBagConstraints.WEST;
gbc.gridy = 0; gbc.gridx = 0;
gbc.gridwidth = 1;
container.add(new JLabel("Name:"), gbc);
gbc.gridx += 2;
// gbc.gridwidth = GridBagConstraints.REMAINDER;
// CommonTextField nameJText = new CommonTextField(40);
container.add(new JTextField(40), gbc);
gbc.gridy++;
gbc.gridwidth = 2;
gbc.gridx = 0;
container.add(new JLabel("Address:"), gbc);
gbc.gridx += 2;
// gbc.gridwidth = GridBagConstraints.REMAINDER;
// CommonTextField addJText = new CommonTextField(40);
container.add(new JTextField(40), gbc);
} // init
} //AccTestApplet
-----------AccTestApplet-----------
-----------Test.html-----------
<!DOCTYPE HTML>
<TITLE>Test JTextfield</TITLE>
<HTML>
<BODY>
<APPLET CODE="AccTestApplet.class" CODEBASE="." WIDTH=400 HEIGHT=300></APPLET>
</BODY>
</HTML>
-----------Test.html-----------
---------- END SOURCE ----------
(Review ID: 165569)
======================================================================
- duplicates
-
JDK-4188906 textfield shrinks to zero width when panel just smaller than textfield width
-
- Closed
-