TextField problems

I am currently working on writing a calculator application, but I am having trouble setting up the display bar that displays the numbers the user has pressed at the top of the calculator. I am trying to set the font size of the textfield and changing the alignment, but the text will just not change. I am also trying to make it uneditable, but I am having no luck there either. The source code is:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Calculator extends JPanel implements ActionListener
     public Calculator()
          //Turn layout manager off
          setLayout(null);
          //Create components
          JTextField displayBar = new JTextField(18);     
          JButton oneButton = new JButton("1");     
          JButton twoButton = new JButton("2");     
          JButton threeButton = new JButton("3");     
          JButton fourButton = new JButton("4");     
          JButton fiveButton = new JButton("5");     
          JButton sixButton = new JButton("6");     
          JButton sevenButton = new JButton("7");     
          JButton eightButton = new JButton("8");     
          JButton nineButton = new JButton("9");
          JButton zeroButton = new JButton("0");          
          JButton clearButton = new JButton("Clr");
          JButton addButton = new JButton("+");
          JButton multiplyButton = new JButton("X");
          JButton subtractButton = new JButton("-");
          JButton divideButton = new JButton("/");
          JButton equalsButton = new JButton("=");
          JButton signButton = new JButton("-/+");
          JButton squarerootButton = new JButton("v-");
          JButton decimalButton = new JButton(".");     
          //Set button sizes - Initialize all buttons to 50x50
          displayBar.setSize(320, 50);
          oneButton.setSize(50,50);
          twoButton.setSize(50,50);
          threeButton.setSize(50,50);
          fourButton.setSize(50,50);     
          fiveButton.setSize(50,50);
          sixButton.setSize(50,50);
          sevenButton.setSize(50,50);
          eightButton.setSize(50,50);     
          nineButton.setSize(50,50);
          zeroButton.setSize(115,50);          
          clearButton.setSize(50,50);
          addButton.setSize(50,50);
          multiplyButton.setSize(50,50);
          subtractButton.setSize(50,50);
          divideButton.setSize(50,50);
          equalsButton.setSize(50,50);
          signButton.setSize(50,50);
          squarerootButton.setSize(50,50);
          decimalButton.setSize(50,50);                    
          //Set button locations
          displayBar.setLocation(15,15);
          oneButton.setLocation(15,210);
          twoButton.setLocation(80,210);
          threeButton.setLocation(145,210);
          fourButton.setLocation(15,145);     
          fiveButton.setLocation(80,145);
          sixButton.setLocation(145,145);
          sevenButton.setLocation(15,80);
          eightButton.setLocation(80,80);     
          nineButton.setLocation(145,80);
          zeroButton.setLocation(15,275);          
          clearButton.setLocation(275,80);
          addButton.setLocation(210,210);
          multiplyButton.setLocation(210,145);
          subtractButton.setLocation(275,210);
          divideButton.setLocation(275,145);
          equalsButton.setLocation(275,275);
          signButton.setLocation(210,275);
          squarerootButton.setLocation(210,80);
          decimalButton.setLocation(145,275);     
          /*THIS IS WHAT IS NOT WORKING*/
          displayBar.setAlignmentX(RIGHT);
          displayBar.setFont(24);
          displayBar.setEditable(false);
          //Add components
          add(displayBar);
          add(oneButton);
          add(twoButton);
          add(threeButton);
          add(fourButton);
          add(fiveButton);
          add(sixButton);
          add(sevenButton);
          add(eightButton);
          add(nineButton);
          add(zeroButton);
          add(clearButton);
          add(addButton);
          add(multiplyButton);
          add(subtractButton);
          add(divideButton);
          add(equalsButton);
          add(signButton);
          add(squarerootButton);
          add(decimalButton);
     public void actionPerformed(ActionEvent e)
private static void startCalculator()
//Create and set up the window.
JFrame frame = new JFrame("Calculator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
Calculator newContentPane = new Calculator();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setSize(350,400);
frame.setVisible(true);
public static void main(String[] args) {
startCalculator();
}

something to think about!!!!!!!
<code>
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Calculator extends JPanel implements ActionListener
     private JButton[] numberButtons;
     private JTextField displayBar;
public Calculator()
//Turn layout manager off
setLayout(null);
//Create components
displayBar = new JTextField(18);
numberButtons = new JButton[10];
for(int i=0;i<10;i++)
     numberButtons[i] = new JButton(String.valueOf(i));
     numberButtons.addActionListener(new ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent e) {
               displayBar.setText(displayBar.getText()+((JButton)e.getSource()).getText());
JButton clearButton = new JButton("Clr");
JButton addButton = new JButton("+");
JButton multiplyButton = new JButton("X");
JButton subtractButton = new JButton("-");
JButton divideButton = new JButton("/");
JButton equalsButton = new JButton("=");
JButton signButton = new JButton("-/+");
JButton squarerootButton = new JButton("v-");
JButton decimalButton = new JButton(".");
//Set button sizes - Initialize all buttons to 50x50
displayBar.setSize(320, 50);
for(int i=0;i<10;i++)
     numberButtons[i].setSize(50,50);
clearButton.setSize(50,50);
addButton.setSize(50,50);
multiplyButton.setSize(50,50);
subtractButton.setSize(50,50);
divideButton.setSize(50,50);
equalsButton.setSize(50,50);
signButton.setSize(50,50);
squarerootButton.setSize(50,50);
decimalButton.setSize(50,50);
//Set button locations
displayBar.setLocation(15,15);
numberButtons[1].setLocation(15,210);
numberButtons[2].setLocation(80,210);
numberButtons[3].setLocation(145,210);
numberButtons[4].setLocation(15,145);
numberButtons[5].setLocation(80,145);
numberButtons[6].setLocation(145,145);
numberButtons[7].setLocation(15,80);
numberButtons[8].setLocation(80,80);
numberButtons[9].setLocation(145,80);
numberButtons[0].setLocation(15,275);
clearButton.setLocation(275,80);
addButton.setLocation(210,210);
multiplyButton.setLocation(210,145);
subtractButton.setLocation(275,210);
divideButton.setLocation(275,145);
equalsButton.setLocation(275,275);
signButton.setLocation(210,275);
squarerootButton.setLocation(210,80);
decimalButton.setLocation(145,275);
/*THIS IS WHAT IS NOT WORKING*/
displayBar.setHorizontalAlignment(JTextField.RIGHT);
displayBar.setFont(displayBar.getFont().deriveFont(24f));
displayBar.setEditable(false);
//Add components
add(displayBar);
for(int i=0;i<10;i++)
     add(numberButtons[i]);
add(clearButton);
add(addButton);
add(multiplyButton);
add(subtractButton);
add(divideButton);
add(equalsButton);
add(signButton);
add(squarerootButton);
add(decimalButton);
public void actionPerformed(ActionEvent e)
private static void startCalculator()
//Create and set up the window.
JFrame frame = new JFrame("Calculator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
Calculator newContentPane = new Calculator();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setSize(350,400);
frame.setVisible(true);
public static void main(String[] args) {
startCalculator();
</code>

Similar Messages

  • HTML Textfield Problem with Image Positions/Image Tag img

    I am using :
    Flash Builder Burito - Flex Hero SDK -  Air 2.5 - Flash Player 10.1
    Hi,
    i have a problem with the normal Textfield.I'm loading html text into it and apply an css stylesheet on it. Everything works fine, but if there is an <img> in the html code, the image is displayed at the wrong position (top left).
    It looks like the Problem is only in Air Applications. I tried the exact same code in an normal actionscript project and tested it in the broweser. Here the images are at the right position.
    Does anybody else has this problem in Air or knows a solution to this?
    Thanks. Laurid
    btw: I tried it on Windows 7 and Android with the same problem.

    Okay, I think I found the solution myself:
    http://www.kirupa.com/forum/showthread.php?t=322233
    For AIR content in the application security sandbox, AIR ignores img  tags in HTML content in ActionScript TextField objects. This is to  prevent possible phishing attacks,
    This does not make any sense to me. Can somebody please explain it to me? I can load images with the loader-class and combine it with my html text. The only thing which does not work is that the text is wrapping aroung the images. So why does this prevent phishing attacks?
    For me this doesn't make sense at all. It's just annoying that you develop an application in Flash and that it's not working the same way in Adobe Air. Now I have to find a complicated work-around myself. Or does anybody know how I can easily wrap text around images?
    Thanks. Laurid

  • Dynamically created textfields problem

    Hi people,
    I have a strange problem here: I want to create textfields
    dynamically that are just big enough to hold the text to display.
    The textfields use a font from the library. I get the metrics of
    the text with TextFormat.getTextExtent(), it seems to work ok.
    However, the last letters of the text are missing in the textfield
    after assigning the text, when the text needs more than 1 line. The
    textfield is sized for 2 lines, but the 2nd line is just empty. I
    applied wordWrap, but the text doesn't show at the 2nd line. This
    seems to be connected to the font that is used: I tested about a
    dozen different types, and only 1 of them displays always the full
    text, with all other fonts, the last 6 or so letters are missing.
    The text property of the textfields holds the complete text; where
    are the last letters?
    So, are there any known issues with textfields created
    dynamically? Or any trick to display all of the text? I'd like to
    use a monospaced font, but all I have tested have this strange
    problem.
    Attached is the code used for creatiing the textfields.
    blemmo

    Yep, the reason is I never tried that. :)
    No... I'm just about to give it a try, but I want to draw a
    fancy border around the textfield (other than the border that comes
    with the textfield), so I guess I'll need the metrics info anyway.
    Another thing is that I want the width to be not more than 150,
    gotta check if that's possible with auto-size. Have to try that
    now... thx for the input!
    blemmo

  • TextField Problem

    I am having a very weird problem. I have created a textfield
    and embedded the fonts. When I set the htmlText propery everything
    works fine until I select the text in the field on stage. After I
    select the text in the field, If I try to modify the htmlText,
    everything disappears. The textfield type is set to dynamic. This
    also only happens if the textfield has fonts embedded. I have also
    discovered that after the htmlText has been changed and the text
    disapears, the maxScrollV and scrollV are reset to 1 but the
    htmlText property retains the data and the textfield.length still
    shows the text is there.
    If anyone knows what is causing this, please let me know. I
    can send someone the project, but since this is for work I'm a
    little hesitant to send it to anyone.

    I have figured out the problem. If you place htmlText into an
    embedded field without any <font> tags, it will make the
    default font in the font tag Times New Roman. This happens even if
    you have set the default text format with a different font name.
    Include a <font> tag with the face value set to a format name
    thats been embedded and it will fix the problem.

  • What is happening here?? TextField problem.

    I'm not new to this and this is driving me crazy.  Can someone please look at this and tell me what I am doing wrong.  There is a Font named Arial embeded in my library, set to export for AS.  This is the relevent part of my document class.  All this does is create a textfield, add it to stage, set the text, load an xml file then attempt to change the text in the text field.  But the text does not change.
    public class Main extends MovieClip {
            public static const EASE_TYPE: Function = gs.easing.Sine.easeIn;
            public static const XML_PATH: String = "EventData.xml";
            public static const TWEEN_TIME: Number = .5;
            public var _messageField: TextField;
            private var _xmlLoader: URLLoader;
            private var _currentIndex: Number;
            private var _messages: Array;
            private var _times: Array;      
            private var _timer: Timer;
            public function Main(): void {
                stage.align = StageAlign.TOP_LEFT;
                stage.scaleMode = StageScaleMode.EXACT_FIT;
                init();
            private function init(): void {
                _times = new Array();
                _messages = new Array();
                _currentIndex = -1;
                _messageField = new TextField();
                _messageField.selectable = true;
                _messageField.width = 955;
                _messageField.x = 15;
                _messageField.y = 0;
                _messageField.defaultTextFormat = new TextFormat( new Arial().fontName, 12, 0xFFFFFF, false, false, false, null, null, TextFormatAlign.LEFT);
                _messageField.antiAliasType = AntiAliasType.ADVANCED;
                _messageField.embedFonts = true;
                this.addChild(_messageField);
                _messageField.text = "Test 1 2 3 . . .";
                    //  Load the xml file containing messages and times to display them.
                _xmlLoader = new URLLoader();
                _xmlLoader.addEventListener(Event.COMPLETE, onXMLload);
                _xmlLoader.load(new URLRequest(XML_PATH));
            private function onXMLload(e: Event): void {
                trace("XML Loaded");
                _messageField.text =". . . 3 2 1 tseT";
                trace( _messageField.text);
    At this point when I run this, I get a trace of "XML Loaded" and ". . . 3 2 1 tesT"  but me text field still says "Test 1 2 3 . . ." when it should say ". . . 3 2 1 tesT"  Why would this happen?   It's as if the text field is not updating.  I wrote this project using CS4 and it worked fine. I am now opening it/running it with CS5, if that matters...
    Any help would be appreciated!

    Hey Kglad, thanks for the response.
    onXMLload() is a method of class Main and _messageField is a member of Class Main.  What specificly do think could be out of scope.  The trace statement for _messageField.text displays the new value, but the swf is still showing the old .text value.
    As far as I know, you can't add a URLLoader to the display list.  It is not a display object, nor does it extend a display object.  How would I go about doing this?

  • Datagrid with textfield problem

    Hello,
    I have a datagrid with a custom cellrenderer that renders the datagrid column as a textfield. This works fine, but when I scroll the datagrid up and down, the text in the text field gets all jumbled. I have attached an image showing before and after scrolling. I am assuming that I need to redraw the datagrid after the scrollbar loses focus or something like that, but I am new to AS3 and unsure how to proceed. Any help greatly appreciated!

    The phone can deal with that. It's just how the input system of most phones work: a sentence starts with a captical letter. you can simply turn that of, just as you would so if you were writing an sms. See your phones manual for that!

  • Dynamic Images based on textfield values

    First time poster LONG time lurker.
    Im using the latest version of livecycle.
    My project is essentially creating a pdf that allows reps to just type in model numbers into a TEXTFIELD and based on the that will populate an image along with a description of what the product is based on the url's H1 tag within source code (More explanation below)
    1st box is a TEXTFIELD
    For this box people will be typing in 7 digit model numbers of products
    2nd is an IMAGE that needs to be dynamic & have the source href based on what was entered in the TEXTFIELD
    Problem is the structure would be http://mywebsite.com/products/[TEXTFIELD].jpg
    ***example 1 : if a user types in 1234567 in TEXTFIELD , then the image should be sourced from
    http://mywebsite.com/products/1234567.jpg
    Also the next crucial part is being able to pull out the data from an H1 tag from a URL's source
    So if I were to go to a product page [http://mywebsite.com/productid?=1234567]
    the product description is placed in a <h1> tag
    I will have to have at least a few rows of these fields so that a rep can just type in the model numbers while the image popup accordingly
    If anyone could please help me out with this I would be forever in your debt.

    based on user authorizationThat is already standard Apex functionality.
    and values in a tableYou can use jQuery to hide a tab. So, you create a tab in Apex, but hide it when necessary when running the page. Something like:
    if (<some condition>) {
       $("#tab_id").hide();
    };Put this in the "Execute when Page Loads" in the JavaScript section on the Page definition.

  • I have a few compile errors. Can someone give me direction?

    I have some compile areas in the following code and I am not really sure how to correct.
    Can someone give guidance? Thanks
    import java.io.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.Window.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.applet.*;
    import java.net.*;
    public class FrontEnd_2 extends Applet{
         private static int appType = 0;
         private Frame FrontEnd_2 = null;
         private Choice nameList = new Choice();
         private Label PipeID = new Label("");
         private TextField pipelineName = new TextField();
         private TextField problem = new TextField();
         private TextField location = new TextField();
         private TextField repairCost = new TextField();
         private Button update = new Button("Update");
         private Button clear = new Button("Clear");
         private Button delete = new Button("Delete");
         private Button exit = new Button("Exit");
         private long idList[] = null;
         public static void main(String args[]){
         appType = 1;
         new FrontEnd_2();
         public FrontEnd_2(){
         Panel p = new Panel(new GridLayout(6,3));
         p.add(new Label());
         p.add(nameList);
         p.add(new Label());
         p.add(new Label("PipeId"));
         p.add(new Label());
         p.add(new Label());
         p.add(new Label("Pipeline Name"));
         p.add(pipelineName);
         p.add(update);
         p.add(new Label("Problem"));
         p.add(problem);
         p.add(clear);
         p.add(new Label("Location"));
         p.add(location);
         p.add(delete);
         p.add(new Label("Repair Cost"));
         p.add(repairCost);
         p.add(exit);
         String data = getData("L0");
              StringTokenizer st = new StringTokenizer(stRetVal, ",");
              nameList.add("[select a name]");
              int size = st.countTokens() / 2;
              idList = new long[size+1];
                   for ( int i=1; i<=size; i++ ) {
                        idList[i] = Long.parseLong(st.nextToken());
                        nameList.add(st.nextToken());
         private String getData(String cmd)
         Socket s = null;
         BufferedReader reader = null;
         BufferedWriter writer = null;
         String sRetVal = " ";
         try{
         s = new Socket("66.24.174.32",1234);
         reader = new BufferedReader(new InputStreamReader(s.getInputStream()));
         writer = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
         writer.write(cmd);
         writer.newLine();
         writer.flush();
         writer.close();
         sRetVal = reader.readLine();
         catch(UnknownHostException ue){
         catch(IOException ioe){
    finally
         writer = null;
         reader = null;
         return sRetVal;
         switch(appType){
         case 0:                                                                           // Applet extends panel
         FrontEnd.add(p);
         break;
         case 1:                                                                           // Application
         FrontEnd_2 = new Frame("Pipeline Inputs");
         FrontEnd_2.addWindowListener(this);
         nameList.addItemListener(this);
         exit.addActionListener(this);
         p.add(exit);
         FrontEnd.add(p);
         FrontEnd.setSize(30,60);
         FrontEnd.setVisible(true);
         break;
         public void actionPerformed(ActionEvent ae){
              if(ae.getSource() == exit){
              fileExit();
              else if (ae.getSource() == clear){
              fileClear();
         public void itemStateChanged(ItemEvent e) {
              int index = nameList.getSelectedIndexOf();
              long id = idList[index];
              String data = getData("R" + id);
              StringTokenizer st = StringTokenizer(data, ",");
              PipeID.setText(st.nextToken());
              problem.setText(st.nextToken());
              location.setText(st.nextToken());
              repairCost.setText(st.nextToken()):
         public void windowActivated(WindowEvent we){     }
         public void windowClosed(WindowEvent we){     }
         public void windowClosing(WindowEvent we){ fileExit();}
         public void windowDeactivated(WindowEvent we){     }
         public void windowDeiconified(WindowEvent we){     }
         public void windowIconified(WindowEvent we){     }
         public void windowOpened(WindowEvent we){     }
         private void fileExit(){
         FrontEnd_2.dispose();
         System.exit(0);

    Some of the errors that I got while compiling your program were the following:
    1) You need to declare your methods outside of your constructor
    2) You are declaring sretval in a private method getData and passing it on to StringTokenizer. You should declare it as an instance variable cuz local variables won't go any farther than the method in which they were declared.
    3) You did not implement WindowListener, ActionListener, ItemListener.
    Some tips: Try to use adapters in an anonymous inner class to implement listeners such as WindowAdapter.
    Use some white space between your code. It makes it a heck of a lot easier to read. Use indentation to show nested statements :)
    Here is the fixed code.
    import java.io.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.Window.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.applet.*;
    import java.net.*;
    public class FrontEnd_2 extends Applet implements WindowListener, ActionListener, ItemListener{
    private static int appType = 0;
    private String sRetVal = " ";
    private Frame FrontEnd_2 = null;
    private Choice nameList = new Choice();
    private Label PipeID = new Label("");
    private TextField pipelineName = new TextField();
    private TextField problem = new TextField();
    private TextField location = new TextField();
    private TextField repairCost = new TextField();
    private Button update = new Button("Update");
    private Button clear = new Button("Clear");
    private Button delete = new Button("Delete");
    private Button exit = new Button("Exit");
    private long idList[] = null;
    * mainline
    public static void main(String args[]){
    appType = 1;
    new FrontEnd_2();
    public FrontEnd_2(){
    Panel p = new Panel(new GridLayout(6,3));
    p.add(new Label());
    p.add(nameList);
    p.add(new Label());
    p.add(new Label("PipeId"));
    p.add(new Label());
    p.add(new Label());
    p.add(new Label("Pipeline Name"));
    p.add(pipelineName);
    p.add(update);
    p.add(new Label("Problem"));
    p.add(problem);
    p.add(clear);
    p.add(new Label("Location"));
    p.add(location);
    p.add(delete);
    p.add(new Label("Repair Cost"));
    p.add(repairCost);
    p.add(exit);
    String data = getData("L0");
    StringTokenizer st = new StringTokenizer(sRetVal, ",");
    nameList.add("[select a name]");
    int size = st.countTokens() / 2;
    long idList = size+1;
    for ( int i=1; i<=size; i++ ) {
    idList = Long.parseLong(st.nextToken());
    nameList.add(st.nextToken());
    switch(appType){
    case 0: // Applet extends panel
    FrontEnd_2.add(p);
    break;
    case 1: // Application
    FrontEnd_2 = new Frame("Pipeline Inputs");
    FrontEnd_2.addWindowListener(this);
    nameList.addItemListener(this);
    exit.addActionListener(this);
    p.add(exit);
    FrontEnd_2.add(p);
    FrontEnd_2.setSize(300,300);
    FrontEnd_2.setVisible(true);
    break;
    }//end constructor
    public void actionPerformed(ActionEvent ae){
    if(ae.getSource() == exit){
    fileExit();
    else if (ae.getSource() == clear){
    fileClear();
    public void itemStateChanged(ItemEvent e) {
    int index = nameList.getSelectedIndex();
    long id = idList[index];
    String data = getData("R" + id);
    StringTokenizer st = new StringTokenizer(data, ",");
    PipeID.setText(st.nextToken());
    problem.setText(st.nextToken());
    location.setText(st.nextToken());
    repairCost.setText(st.nextToken());
    public void windowActivated(WindowEvent we){ }
    public void windowClosed(WindowEvent we){ }
    public void windowClosing(WindowEvent we){ fileExit();}
    public void windowDeactivated(WindowEvent we){ }
    public void windowDeiconified(WindowEvent we){ }
    public void windowIconified(WindowEvent we){ }
    public void windowOpened(WindowEvent we){ }
    private void fileExit(){
    FrontEnd_2.dispose();
    System.exit(0);
    private void fileClear(){
    //do something here
    //start of getData
    private String getData(String cmd){
    Socket s = null;
    BufferedReader reader = null;
    BufferedWriter writer = null;
    try{
    s = new Socket("66.24.174.32",1234);
    reader = new BufferedReader(new InputStreamReader(s.getInputStream()));
    writer = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
    writer.write(cmd);
    writer.newLine();
    writer.flush();
    writer.close();
    sRetVal = reader.readLine();
    }//end try
    catch(UnknownHostException ue){
    catch(IOException ioe){
    finally{
    writer = null;
    reader = null;
    return sRetVal;
    }//end getData

  • How to call some function by pressing Enter in JTextField

    Hi
    I have a following problem.
    In my app existing two JTextFields tfField1 and tfField2
    How to make when I type some text into tfField1 and press Enter the cursor will appear in tfField2?
    Setting the cursor into tfField2 is not a problem, I have realized this with tfField2.requestFocusInWindow();
    My problem is how to call this funktion [tfField2.requestFocusInWindow()] by pressing Enter on the keyboard

    Thanks a lot
    You are welcome.
    >
    I have an another question if you don't mindI don't mind at all. In the future, though, I recommend that you start a new thread if you have a completely different question.
    >
    I have 2 JFrames
    In JFrame 1 i have a button which opens JFrame2
    How to make that only JFrame2 will be active until it
    will be closed (so when JFrame2 is opened i can't do
    anything with the first JFrame1)
    Use a modal dialog instead of the second JFrame. Almost as easy as the textfield problem :-)
    You can read more about dialogs here:
    [url http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html]How to Make Dialogs

  • Generate Components Dynamically

    Dear All,
    Case:
    In my application i have a textfield
    Problem:
    Depending on the number inserted in that text field (i.e 4) iam generate 4 labels and 4 textfields and add this components on a panel like that
    | A | Enter your text Here |
    | B | Enter your text Here |
    | C | Enter your text Here |
    | D | Enter your text Here |
    suppose the A,B,C,D is the labels and beside it the textfields
    Need:
    I need any help in how to dynamically generate this components and what is the best layout that help me in adding components, any kind of help is welcomed.
    Thanks in Advance

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class OnDemand
        static int labelCount = 0;
        public static void main(String[] args)
            final JPanel panel = new JPanel(new GridBagLayout());
            final GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(2,2,2,2);
            final JTextField entryField = new JTextField(4);
            JButton addButton = new JButton("add");
            addButton.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    int number;
                    try
                        number = Integer.parseInt(entryField.getText());
                    catch(NumberFormatException nfe)
                        System.out.println(nfe.getMessage());
                        return;
                    addComponents(number, panel, gbc);
            JPanel northPanel = new JPanel();
            northPanel.add(entryField);
            northPanel.add(addButton);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(northPanel, "North");
            f.getContentPane().add(new JScrollPane(panel));
            f.setSize(400,300);
            f.setLocation(200,200);
            f.setVisible(true);
        private static void addComponents(int n, JPanel panel, GridBagConstraints gbc)
            for(int i = 0; i < n; i++)
                JLabel label = new JLabel("Label " + ++labelCount);
                JTextField tf = new JTextField(8);
                gbc.gridwidth = gbc.RELATIVE;
                gbc.anchor = gbc.EAST;
                panel.add(label, gbc);
                gbc.gridwidth = gbc.REMAINDER;
                gbc.anchor = gbc.WEST;
                panel.add(tf, gbc);
                panel.revalidate();
                panel.repaint();
    }

  • Adding CDATA to an existing xml and flash asset

    Hi, I am a front end web designer/developer and
    analyst...struggling with putting an accordian flash xml menu
    together. I have it done except I need to add a simple trademark
    symbol circle with r. I am struggling with how to do this since I
    am not savvy in actioncript. I assume the best way is to add it is
    with a CDATA child node, but do not know how or whatever is the
    best way to get this done since am on a tight deadline. I need
    someone to explain step by step what I have to do to get this
    simple addition resolved. Attached are the links to home page and
    code for the xml file. The left navigation is the asset that I need
    to add the trademark symbol under about, about ADHERE. Thanks so
    much in advance!!!!!!
    [URL=http://www.nodcreative.com/natrecor_sliced/natrecor_index.html]index
    page with flash xml menu asset[/URL]
    xml code:
    <?xml version="1.0" encoding="UTF-8"?>
    <accodion>
    <item name="HOME">
    </item>
    <item name="ABOUT">
    <item name= "ABOUT
    ADHERE<![CDATA[write]]>"></item>
    <item name="Medical Information" url="
    http://www.jnj.com?ref=Random">
    </item>
    <item name="About SCIOS" url="
    http://www.jnj.com?ref=Random">
    </item>
    </item>
    <item name="INTERACTIVE DOSING INFORMATION">
    <item name="Indications and Usage" url="
    http://www.jnj.com?ref=Random"></item>
    <item name="Contraindications" url="
    http://www.jnj.com?ref=Random"></item>
    <item name="Warnings" url="
    http://www.jnj.com?ref=Random"></item>
    <item name="Dosage and Administration" url="
    http://www.jnj.com?ref=Random"></item>
    </item>
    <item name="RESOURCES AND TOOLS">
    <item name="NATRECOR PI" url="
    http://www.jnj.com?ref=Random"></item>
    <item name="About Heart Failure" url="
    http://www.jnj.com?ref=Random"></item>
    <item name="Stages of Heart Failure" url="
    http://www.jnj.com?ref=Random"></item>
    <item name="NATRECOR Dosing Information" url="
    http://www.jnj.com?ref=Random"></item>
    <item name="Patient Management Resources" url="
    http://www.jnj.com?ref=Random"></item>
    </item>
    <item name="US PRESCRIBING INFORMATION">
    </item>
    <item name="IMPORTANT SAFETY INFORMATION
    ref=http://www.jnj.com">
    </item>
    <item name="REGISTRATION ref=http://www.jnj.com">
    </item>
    </accodion>
    FLASH actionscript is as follows:
    // The accordion
    var accordion = this
    // The item list
    var itemList = []
    // SETTINGS
    //-------------PROPERTIES----------------
    // Separation between the buttons
    var separation = 1.5
    // Tabulation between the buttons and the margin
    var tabulation = 10
    // if true, it cant be more than one items opened at the same
    time (only for the first buttons, POWERFUL, MENU ,ACCORDION, ets).
    var autoClose = true
    // if true, it cant be more than one subItems opened at the
    same time.
    var subItemAutoClose = true
    // if true, open and close all the subItems at the same time.
    var openAll = false
    // The height of the button
    var itemHeight = 21
    // The width of the button
    var itemWidth = 230
    // If true, show the light over the button
    var light = true
    // The ease of the menu opening
    var openEase = 2.5
    // The ease of the menu closing
    var closeEase = 2.5
    // The rollOut color fade speed
    var rollOutFade = 8
    //-------------COLORS----------------
    // The color of the button
    var buttonColor = 0xa
    // The roll over color
    var rollOverColor = 0xCCCCCC
    // The arrow color
    var arrowColor = 0xCCCCCC
    // The arrow color on roll over
    var rollOverArrowColor = 0x000000
    // The text color
    var TextColor = 0xFFFFFF
    // The text color on roll over
    var rollOverText = 0x000000
    // LOADING XML
    // The xml data
    var xmlSource:XML = new XML
    // Loading the xml
    xmlSource.onLoad = function(success:Boolean):Void {
    // When the load finishs...
    if (success) {
    // The first node of the xml
    xmlRoot = xmlSource.firstChild
    // The item nodes
    xmlItems = xmlRoot.childNodes
    // The total of items
    total = xmlItems.length
    // Creating the buttons
    for (i=0; i<total; i++){
    // Attaching the buttons
    accordion.attachMovie("item", "item" + i, i)
    // The button reference
    itemList
    = accordion["item"+i]
    // The first node of the item node
    itemList.xmlRoot = xmlItems
    // The separation between subitems
    itemList.separation = separation
    // Tabulation between the subitems and the margin
    itemList
    .tabulation = tabulation
    // subItems auto close
    itemList.subItemAutoClose = subItemAutoClose
    // The subitems height
    itemList
    .itemHeight = itemHeight
    // The subitems width
    itemList.itemWidth = itemWidth
    // shows/hides the subitems light
    itemList
    .light = light
    // The subitems color
    itemList.buttonColor = buttonColor
    // The roll over color
    itemList
    .rollOverColor = rollOverColor
    // The arrow color
    itemList.arrowColor = arrowColor
    // the arrow color on roll over
    itemList
    .rollOverArrowColor = rollOverArrowColor
    // The text color
    itemList.TextColor = TextColor
    // The roll over text color
    itemList
    .rollOverText = rollOverText
    // the opening easing
    itemList.openEase = openEase
    // The closing easing
    itemList
    .closeEase = closeEase
    // The roll over fade speed
    itemList.rollOutFade = rollOutFade
    // open all
    itemList
    .openAll = openAll
    // ignore white
    xmlSource.ignoreWhite = true;
    // Loads the .xml file
    xmlSource.load("accordion.xml");
    // Aligning the items each one below the other
    this.onEnterFrame=function(){
    // Does the align to ALL the items
    for (i=1; i<total; i++){
    // Aligning the items
    itemList._y = itemList[i-1]._y +
    itemList[i-1].mask._height + itemList[i-1].button._height +
    separation
    // The cursor position
    cursor._x = _xmouse
    cursor._y = _ymouse
    // Opens the items
    onMouseDown = function (){
    // Does this to all the buttons
    for (i=0; i<total; i++){
    // If is clicked
    if (itemList
    .button.hitTest(cursor)){
    // Shows the current item
    showCurrent(itemList)
    // Shows the button clicked
    showCurrent=function(current){
    // Does this to all the buttons
    for (i=0; i<total; i++){
    // Does this to all the buttons exept the clicked
    if (itemList
    !=current){
    // Close the other items if autoclose = true
    if (autoClose){
    // Close the other items
    itemList.openBox=false
    // fades the roll over effect of the other items
    itemList
    .over = false
    //Does this to the clcked item only
    } else {
    // If it has sub items
    if (total>0){
    //Hides them if its open
    if (itemList.openBox){
    itemList
    .openBox=false
    //Shows them if its closed
    } else {
    itemList.openBox=true
    // If it has no subitems goes to the link
    } else {
    getURL(xmlRoot.attributes.url, _self)

    Please don't cross-post in a bunch of forums. Also when
    adding code to a post, please use the attach code button. That
    keeps the formatting and makes it easier to read. Your code is far
    too long and way to unformatted to really understand quickly.
    I don't know why you would need a CDATA node to get the
    registered symbol. If the XML file you are working with is saved as
    unicode (UTF-8) the symbol should come across just fine. Just
    putting the UTF-8 at the beginning doesn't tell whatever program
    you are using to save as UTF-8!
    Do you know how to make the registered symbol? On windows it
    is ALT -0174 (use the keypad for those numbers).
    Once you've got the symbol in your XML the next step is to
    check if Flash is loading it correctly. When you are in the testing
    environment go to the Debug menu and select List Variables. The
    trace window will show all the variables -- and there are probably
    a lot! Search/Find something close to the symbol and see if the
    trace window shows the symbol correctly. If it does then Flash is
    readying it correctly and if it isn't showing you have problems
    with your textfield. If it isn't showing correctly then your XML
    file isn't UTF-8.
    If it is textfield problems I wouldn't know what to do since
    it is inside a component. Post back with your findings.

  • Dispatching Custom Event

    Hello everybody,
    Task: I want to enter a message in input text field and
    write it in the dynamic using a custom event dispatching.
    Solution: I have 2 textfields on the stage.
    One textfield is an input text field the other is a dynamic
    text field which will server just to display text.
    on the flash in the first frame I made this code:
    // mb is the instance name of the dynamic text field already
    placed on the stage
    var messageBoard:MsgBoard = new MsgBoard(mb);
    // u1 is the input text field placed on the stage
    var user1:UserInput = new UserInput(u1);
    Also I wrote 3 very simple classes.
    1. UserInput.as // input textfield class that listens to
    input and dispatches a custom event
    2. MsgEvnt.as // custom event class the instance of which is
    dispatched
    3. MsgBoard.as // class that listens to the new event and
    once it occurs adding event message to the textfield
    Problem: Somehow it doesn't work. I actually made it work by
    making a listener the same object that dispatches the event. But I
    want to understand why it doesn't works the way I showed above. I
    browsed a lot of forums and found that all the people use to listen
    by the same object that is dispatching. I think it's like talking
    with yourself isn't it?
    Thanks everybody who will reply and I hope it will help
    someone who will read!

    your event is dispatched within UserInput scope and MsgBoard
    is not within UserInput scope so it's not going to receive that
    event. ie, a UserInput instance is not accessible to MsgBoard.
    you may have a basic misunderstanding: events that are
    dispatched are not like radio signals that are transmitted and
    anyone with a listener (radio) can hear them.
    when you dispatch an event using actionscript, it is
    dispatched by an object (or sometimes by a class) and that event
    can only be detected by the dispatching object (or class).

  • Problem of defining value to a textfield in MovieClip

    hello,dear everyone
    there is problem that realy confused me.that is the
    textfield(or other display objects) in MovieClip can't be defined
    when i jumpto that frame.check these simple code:
    mc.stop()
    function goNext(evt:Event){
    mc.nextFrame()
    dosth()
    function dosth()
    if(mc.currentFrame==2)
    mc.mytext.text="hello"
    nextBT.addEventListener("click",goNext)
    the mc is a simple MC that have 2 frames,and the textfield
    object is in the second frame.
    and what i try to do is when i clicked the button,the mc
    jumpto the second frame.and i define a value to that textfield.but
    it's failed when i try to do like that.
    as i debug the program.i found that when i define the value
    to the textfield,that textfield is a Null Object(should be the
    TextField object).not only the textfield not work,but also other
    elements such as Button objects.
    so,i am thinking that must because the objects are too late
    to initialized before they be used.maybe there are some event can
    tell me that all elements has been initialized,as i can use them
    then.what do you think,my friend?

    If all of the code you have is in the first frame, then it
    has processed long before anything ever moved to the second frame.
    What you could try is to have a variables layer that extends
    both frames, and assign the value of the textfield text to that
    variable. Make the textfield associate with that variable (in the
    properties section for it), So when the movieclip moves to the
    second frame the text field should automatically acquire the
    variable value.
    I may not have interpretted your problem correctly, so you
    might have to clarify things if I missed the target.

  • Problem with TextField formatting

    I'm having a little bit of a problem with this very basic bit
    of code. The following code works fine: (I apologize for not having
    it in a format that may be more suitable)
    this.createTextField("my_text", this.getNextHighestDepth(),
    10, 70, 400, 100);
    my_text.text = "This is my TextField.";
    //my_text.embedFonts = true;
    However, for some reason, this doesn't work. I'm baffled by
    why uncommenting this simple line of code makes it not show up:
    this.createTextField("my_text", this.getNextHighestDepth(),
    10, 70, 400, 100);
    my_text.text = "This is my TextField.";
    my_text.embedFonts = true;
    Any help would be appreciated.

    My guess is that you forgot a few things to work with
    embedded fonts...
    1) Have you embedded the font you want to use inside your
    library and given it a unique id.
    2) If you did #1, try this...

  • Problem with expanding textfield in Adobe LiveCycle Designer

    I've got an urgent problem with Adobe LiveCycle Designer and I really could use some help. The problem is that I'm trying to get my textfield expandable, but whatever I try, it's not working. What I'm trying to get done is that you can fill in a textfield, and when there is more text than the size of the field, the textfield expands to make the text fit in the field.
    I tried a whole lot of things:
    placing the textfield in a subform
    expand to fit (height)
    allow multiple lines
    allow page breaks
    flowed/positioned
    etc.
    The strange thing is, that no matter what I try to adjust, I can't change anything in the pagination tab. Maybe that is the problem, but I don't know what to do, to change that.
    In the examples of Adobe itself (Purchase Form) is an example of a textfield that sort of behaves as I want it to, BUT the problem is that that textfield in the subform has to be triggered to appear by a button (add comments) and that is what I don't want. I want the textfield to be visible from the beginning. But in that example you CAN see the pagination tab and make changes in it.
    I searched a lot in the Adobe Helpfiles of Designer, and I even bought and read/studied the book 'Creating Dynamic Forms with Adobe LiveCycle Designer', but still I'm not able to get this done.
    Is there anyone who can help me?
    Thanks in advance,
    Sterre

    I am creating my first .pdf with no training. I first converted a word doc of our form into a .pdf. Modified everything and thought I was the "bomb" for figuring it out. Then I tried to use the form and where I had "allowed multiple lines" I realized that it would allow that but not display it or print it except for what was showing.
    In researching for a solution, this site said to use "expand to fit". After much frustration I realized that this feature is only available if you created the form from scratch in adobe.
    I have figured out, somewhat, how to create the form and get the field to move with the text but I need the entire form to adjust to the input. Can't have one specific field expand into the rest of the form.
    I did some more research on this site, and it looks like the solution has something to do with 'subforms'. No idea what to do.
    If anyone knows if there is a way to do this with a converted doc (since I already have that completed) I would GREATLY appreciate it. If it isn't possible, could someone walk me through how to do it or provide a reference for a "barney style" walk through?
    Appreciate ANY assistance you can provide. THANKS! Guess I need to sign up for an Adobe Pro class. BTW I'm working on LiveCyle 8.0

Maybe you are looking for

  • Using a ethernet external Maxtor Hard Drive (Network Attached Storage)

    Does anyone know if I can use a NAS (Network Attached Storage - in this case a 1 Tb Maxtor external drive with ethernet connection) and have my iMac G5 and Macbook backup to this drive on the same ethernet segment using Time Machine ? (both computers

  • Read timed out error while executing a web service

    hi, i have a remote funtion module which takes around 31 seconds in AAD (developing enviroment) server which has around 4 select queries,the same RFC is taking around 25 mins in AAT (testing environment) due to more data. Now when i am releasing the

  • Cursor will not open web page icons after upgrade, icons are not changeing cursor and page sliders not working. .

    Hi , Since I upgraded none of the web pages I visit will function correctly. In Yahoo mail I cannot opem the search box, Similiary in Google I have the same problem, In addition other icons are not recognised as the curson does not change and my page

  • Screen Exit for t-code F-06

    Dear All I have an requirement like I need to add a field in the t-code f-06, in the first screen it self, they need a field to add from the table BKPF. I have searched for any screen exits for the package FBAS, but I am unable to find out. Please gu

  • Why is Flash Media Live showing multiple windows?

    When you look into a mirror, and there is one is in front and behind you, you see them seeming to loop forever. That's what's going on with me right now in Flash. How do I stop this, or adjust the focus to one spot without that effect? For context, I