HELP !!! JTextArea in a JDialog !!!

I have a JTextArea in a Dialog but there is no scrollbars !!!
How can i create a scrollbar, please help !!!

The scroll bar kicks in when required.
L.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
package diatextscroll;
import java.awt.*;
import javax.swing.*;
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
public class Dialog1 extends JDialog {
private JPanel panel1 = new JPanel();
private BorderLayout borderLayout1 = new BorderLayout();
private JScrollPane jScrollPane1 = new JScrollPane();
private JTextPane jTextPane1 = new JTextPane();
public Dialog1(Frame frame, String title, boolean modal) {
super(frame, title, modal);
try {
jbInit();
pack();
setVisible(true);
catch(Exception ex) {
ex.printStackTrace();
public Dialog1() {
this(null, "", false);
private void jbInit() throws Exception {
panel1.setLayout(borderLayout1);
jTextPane1.setText("jTextPane1");
getContentPane().add(panel1);
panel1.add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(jTextPane1, null);
public static void main(String[] args) {
Dialog1 dlg = new Dialog1();

Similar Messages

  • Accessing the JTextArea of a JDialog

    hi
    I have a frame with a button and a JDialog with a JTextArea.When i click the button in the frame i should append some datas to the JTextArea in the JDialog.How can i access the JTextArea component of the JDialog from the frame.
    thanks

    Hai
    do't make your JDialog as model dialog. make it setModel(false) and
    create a method with parameter string to update textArea with string
    and call the method in button click event with some string data

  • Need help in Simple Java JDialog...

    have 3 classes..
    One class extend JFrame
    One class extend JPanel
    One class extend JDialog
    My JFrame is like my Main Frame...
    I have my JPanel that is always changing in my JFrame..
    How do i pass the JFrame into my JDialog constructor???
    (btw, is upon one of my JPanel click button, my JDialog appears)
    Thanks.

    have 3 classes..
    One class extend JFrame
    One class extend JPanel
    One class extend JDialog
    My JFrame is like my Main Frame...
    I have my JPanel that is always changing in my
    JFrame..
    How do i pass the JFrame into my JDialog
    constructor???
    (btw, is upon one of my JPanel click button, my
    JDialog appears)
    Thanks.You can pass the reference of JFrame in JDialog constructor as below:
    1) JDialog dialog = new JDialog(ClassName.this, "Title', true);
    where ClassName is the name of class that extends the JFrame. Thus you can capture reference of the parent.
    2) You can also get reference of JFrame by invoking method on your panel as:
    Container parent = jPanel.getParent();
    JDialog dialog = new JDialog(parent , "Title', true);
    where jPanel is instance of your JPanel.
    Post whether u need anything else.

  • HELP moving a modal JDialogs parent window

    Hello All,
    I have an application which presents the user with a JDialog for data collection. The JDialog is modal but I have to be able to move the Dialogs parent frames. Not enter data, just move them. It seems sensible that the user should be able to see what was on the parent whilst entering into the modal dialog. I don't really want the user to have to close the dialog, move the parent and reopen the dialog. not very friendly.
    I know I could set the dialog as non-modal and block every event under the sun to all parents but that is the last resort and don't think I should have to do that.
    I am thinking I could get hold of the glasspane or what ever blocks the mouse events and resize it to ignore the title bar. (obviouosly I would have to block the min/max/kill buttons, but I can deal with that).
    Any ideas??
    Dr_n35s

    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance).
    *Do NOT click the Reset button on the Safe mode start window or otherwise make changes.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • How do I display a JDialog with a JTextArea in it?

    Hello.
    How do I display a JDialog with a JTextArea in it?

    http://java.sun.com/docs/books/tutorial/uiswing/mini/index.html
    import javax.swing.*;
    import java.awt.*;
    public class Test extends JDialog{
         public Test(){
              JPanel contentPane = new JPanel(new BorderLayout());
              JTextArea ta = new JTextArea();
              ta.setText("JDialog with a JTextArea in it");
              setContentPane(contentPane);
              contentPane.add(ta);
              setSize(300,300);
              setVisible(true);
         public static void main(String[] args){
              new Test();
    }     

  • JDialog + RequestFocus

    Hi all,
    how do i assign the focus to a JComponent (JTextArea) in a JDialog on opening the JDialog??
    Tried calling textArea.requestFocusInWindow() in an overridden dialog.setVisible(..).
    Thanks for any help.
    Cheers,
    Mark

    Sorry, :(, no more ideas.
    One thing only, try this to see how the focus is changing between components. Could help.
        KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(new FocusChangeListener());
        KeyboardFocusManager.getCurrentKeyboardFocusManager().addVetoableChangeListener(new FocusVetoableChangeListener());
        class FocusChangeListener implements PropertyChangeListener {
            public void propertyChange(PropertyChangeEvent evt) {
                Component oldComp = (Component)evt.getOldValue();
                Component newComp = (Component)evt.getNewValue();
                if ("focusOwner".equals(evt.getPropertyName())) {
                    if (oldComp == null) {
                        // the newComp component gained the focus
                    } else {
                        // the oldComp component lost the focus
                } else if ("focusedWindow".equals(evt.getPropertyName())) {
                    if (oldComp == null) {
                        // the newComp window gained the focus
                    } else {
                        // the oldComp window lost the focus
        class FocusVetoableChangeListener implements VetoableChangeListener {
            public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
                Component oldComp = (Component)evt.getOldValue();
                Component newComp = (Component)evt.getNewValue();
                if ("focusOwner".equals(evt.getPropertyName())) {
                    if (oldComp == null) {
                        // the newComp component will gain the focus
                    } else {
                        // the oldComp component will lose the focus
                } else if ("focusedWindow".equals(evt.getPropertyName())) {
                    if (oldComp == null) {
                        // the newComp window will gain the focus
                    } else {
                        // the oldComp window will lose the focus
                boolean vetoFocusChange = false;
                if (vetoFocusChange) {
                    throw new PropertyVetoException("message", evt);
            }This piece of code helped me when I had a focus problem and I sow then how the events get through the system and figured out to use invokeLater().

  • Focus

    Hi All...
    Got a bit of a problem with Internet Explorer and JDialog.
    I have an applet with a modal dialog (JDialog). Problem is: if I switch to another app running on my PC and then back to the my applet running in IE, it appears frozen as the dialog is still open but hidden behing all other windows. The only way to get back to it is to minimise all windows.
    Any ideas how to get the dialog to pop to the fromt as soon as IE (or the applet) gets the focus?
    Many thanks for your help
    Patrick

    HI Patrick
    Unforunately JDIalogs need JFrames to display over the front.
    There is a round about trick which worked out for me, as follows :
    Maintain a vector , that stores all the dialogs that are currently showing
    Every time u display a dialog display in the following manner.
    Ex:
    //create the dialog
    dialogsVect.add(dialog);
    dialog.show();
    dialog.remove();
    Override the paint(Graphics g) method of ur main applet like this :
    public void paint(Graphics g)
    super.paint(g);
    //ur code if Any.
    for(int i=0; i <dialogsVect.size();i++)
    JDialog dlg = (JDialog) dialogsVect.elementAt(i);
    dlg.toFront();
    Check Out.

  • JEditorPane Autosize in JDK 1.1.8

    Hi,
    I am using a HTML file in local drive to be displayed using JEditorPane, which is added in JPanel. This is displayed in JDialog.
    The contents(message) from HTML file are displayed, fine. The problem is - the contents of HTML file vary, but the JDialog size is not varying accordingly. User has to pull the window to maximize the size. Is there any API to help auto-size the JDialog or the JEditorPane?
    I could use JDialog.setSize(w,h) - But, I am not sure how to fix the values of width and height, I want this to dynamically change based on the HTML file contents.
    How do I adjust the size of JDialog through the code, based on the contents of HTML file?
    Any help would be appreciated.
    Thanks!of HTML file?
    Any help would be appreciated.
    Thanks!

    I have this same problem - I'm trying to implement multiple concatenated JEditorPanes within a single vertical scrollpane. I need to adjust the height of each of the JEditorPanes so that the scrollbar in the scrollpane will work for all of the JEditorPanes. Any thoughts? Thanks a ton...
    Max

  • How to set Focus for one component on Dialog

    Hi all.
    I have a problem and need a help
    I have a JDialog
    I add some components on it. Includes button, textfield...
    after i set
         _textField.requestFocus()When Dialog show, it always focus at first component, not at the component i set.
    Please help me.
    Thanks in advance
    Diego

    Perhaps Swings threading ruins your focus request, and trying invokeLater may be worthwhile...
    Note that [requestFocusInwindow()|http://java.sun.com/javase/6/docs/api/javax/swing/JComponent.html#requestFocusInWindow()] is to be preferred over requestFocus according to the API docs.
    Edited by: isocdev_mb on Mar 4, 2010 6:05 AM

  • Need help with JTextArea and Scrolling

    import java.awt.*;
    import java.awt.event.*;
    import java.text.DecimalFormat;
    import javax.swing.*;
    public class MORT_RETRY extends JFrame implements ActionListener
    private JPanel keypad;
    private JPanel buttons;
    private JTextField lcdLoanAmt;
    private JTextField lcdInterestRate;
    private JTextField lcdTerm;
    private JTextField lcdMonthlyPmt;
    private JTextArea displayArea;
    private JButton CalculateBtn;
    private JButton ClrBtn;
    private JButton CloseBtn;
    private JButton Amortize;
    private JScrollPane scroll;
    private DecimalFormat calcPattern = new DecimalFormat("$###,###.00");
    private String[] rateTerm = {"", "7years @ 5.35%", "15years @ 5.5%", "30years @ 5.75%"};
    private JComboBox rateTermList;
    double interest[] = {5.35, 5.5, 5.75};
    int term[] = {7, 15, 30};
    double balance, interestAmt, monthlyInterest, monthlyPayment, monPmtInt, monPmtPrin;
    int termInMonths, month, termLoop, monthLoop;
    public MORT_RETRY()
    Container pane = getContentPane();
    lcdLoanAmt = new JTextField();
    lcdMonthlyPmt = new JTextField();
    displayArea = new JTextArea();//DEFINE COMBOBOX AND SCROLL
    rateTermList = new JComboBox(rateTerm);
    scroll = new JScrollPane(displayArea);
    scroll.setSize(600,170);
    scroll.setLocation(150,270);//DEFINE BUTTONS
    CalculateBtn = new JButton("Calculate");
    ClrBtn = new JButton("Clear Fields");
    CloseBtn = new JButton("Close");
    Amortize = new JButton("Amortize");//DEFINE PANEL(S)
    keypad = new JPanel();
    buttons = new JPanel();//DEFINE KEYPAD PANEL LAYOUT
    keypad.setLayout(new GridLayout( 4, 2, 5, 5));//SET CONTROLS ON KEYPAD PANEL
    keypad.add(new JLabel("Loan Amount$ : "));
    keypad.add(lcdLoanAmt);
    keypad.add(new JLabel("Term of loan and Interest Rate: "));
    keypad.add(rateTermList);
    keypad.add(new JLabel("Monthly Payment : "));
    keypad.add(lcdMonthlyPmt);
    lcdMonthlyPmt.setEditable(false);
    keypad.add(new JLabel("Amortize Table:"));
    keypad.add(displayArea);
    displayArea.setEditable(false);//DEFINE BUTTONS PANEL LAYOUT
    buttons.setLayout(new GridLayout( 1, 3, 5, 5));//SET CONTROLS ON BUTTONS PANEL
    buttons.add(CalculateBtn);
    buttons.add(Amortize);
    buttons.add(ClrBtn);
    buttons.add(CloseBtn);//ADD ACTION LISTENER
    CalculateBtn.addActionListener(this);
    ClrBtn.addActionListener(this);
    CloseBtn.addActionListener(this);
    Amortize.addActionListener(this);
    rateTermList.addActionListener(this);//ADD PANELS
    pane.add(keypad, BorderLayout.NORTH);
    pane.add(buttons, BorderLayout.SOUTH);
    pane.add(scroll, BorderLayout.CENTER);
    addWindowListener( new WindowAdapter()
    public void windowClosing(WindowEvent e)
    System.exit(0);
    public void actionPerformed(ActionEvent e)
    String arg = lcdLoanAmt.getText();
    int combined = Integer.parseInt(arg);
    if (e.getSource() == CalculateBtn)
    try
    JOptionPane.showMessageDialog(null, "Got try here", "Error", JOptionPane.ERROR_MESSAGE);
    catch(NumberFormatException ev)
    JOptionPane.showMessageDialog(null, "Got here", "Error", JOptionPane.ERROR_MESSAGE);
    if ((e.getSource() == CalculateBtn) && (arg != null))
    try{
    if ((e.getSource() == CalculateBtn) && (rateTermList.getSelectedIndex() == 1))
    monthlyInterest = interest[0] / (12 * 100);
    termInMonths = term[0] * 12;
    monthlyPayment = combined * (monthlyInterest / (1 - (Math.pow (1 + monthlyInterest,  -termInMonths))));
    lcdMonthlyPmt.setText(calcPattern.format(monthlyPayment));
    if ((e.getSource() == CalculateBtn) && (rateTermList.getSelectedIndex() == 2))
    monthlyInterest = interest[1] / (12 * 100);
    termInMonths = term[1] * 12;
    monthlyPayment = combined * (monthlyInterest / (1 - (Math.pow (1 + monthlyInterest,  -termInMonths))));
    lcdMonthlyPmt.setText(calcPattern.format(monthlyPayment));
    if ((e.getSource() == CalculateBtn) && (rateTermList.getSelectedIndex() == 3))
    monthlyInterest = interest[2] / (12 * 100);
    termInMonths = term[2] * 12;
    monthlyPayment = combined * (monthlyInterest / (1 - (Math.pow (1 + monthlyInterest,  -termInMonths))));
    lcdMonthlyPmt.setText(calcPattern.format(monthlyPayment));
    catch(NumberFormatException ev)
    JOptionPane.showMessageDialog(null, "Invalid Entry!\nPlease Try Again", "Error", JOptionPane.ERROR_MESSAGE);
    }                    //IF STATEMENTS FOR AMORTIZATION
    if ((e.getSource() == Amortize) && (rateTermList.getSelectedIndex() == 1))
    loopy(7, 5.35);
    if ((e.getSource() == Amortize) && (rateTermList.getSelectedIndex() == 2))
    loopy(15, 5.5);
    if ((e.getSource() == Amortize) && (rateTermList.getSelectedIndex() == 3))
    loopy(30, 5.75);
    if (e.getSource() == ClrBtn)
    rateTermList.setSelectedIndex(0);
    lcdLoanAmt.setText(null);
    lcdMonthlyPmt.setText(null);
    displayArea.setText(null);
    if (e.getSource() == CloseBtn)
    System.exit(0);
    private void loopy(int lTerm,double lInterest)
    double total, monthly, monthlyrate, monthint, monthprin, balance, lastint, paid;
    int amount, months, termloop, monthloop;
    String lcd2 = lcdLoanAmt.getText();
    amount = Integer.parseInt(lcd2);
    termloop = 1;
    paid = 0.00;
    monthlyrate = lInterest / (12 * 100);
    months = lTerm * 12;
    monthly = amount *(monthlyrate/(1-Math.pow(1+monthlyrate,-months)));
    total = months * monthly;
    balance = amount;
    while (termloop <= lTerm)
    displayArea.setCaretPosition(0);
    displayArea.append("\n");
    displayArea.append("Year " + termloop + " of " + lTerm + ": payments\n");
    displayArea.append("\n");
    displayArea.append("Month\tMonthly\tPrinciple\tInterest\tBalance\n");
    monthloop = 1;
    while (monthloop <= 12)
    monthint = balance * monthlyrate;
    monthprin = monthly - monthint;
    balance -= monthprin;
    paid += monthly;
    displayArea.setCaretPosition(0);
    displayArea.append(monthloop + "\t" + calcPattern.format(monthly) + "\t" + calcPattern.format(monthprin) + "\t");
    displayArea.append(calcPattern.format(monthint) + "\t" + calcPattern.format(balance) + "\n");
    monthloop ++;
    termloop ++;
    public static void main(String args[])
    MORT_RETRY f = new MORT_RETRY();
    f.setTitle("MORTGAGE PAYMENT CALCULATOR");
    f.setBounds(600, 600, 500, 500);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
    }need help with displaying the textarea correctly and the scroll bar please.
    Message was edited by:
    new2this2020

    What's the problem you're having ???
    PS.

  • Problem with JTextArea or is it my code, Help!!!

    Hi,
    I am going crazy. I am sending a message to a JTextArea and I get some very wierd things happening? I really need help because this is driving me crazy. Please see the following code to see my annotations for the problems. Has anyone else experienced problems with this component?
    Thanks,
    Steve
    // THIS IS THE CLASS THAT HANDLES ALL OF THE WORK
    public class UpdateDataFields implements ActionListener {     // 400
         JTextArea msg;
         JPanel frameForCardPane;
         CardLayout cardPane;
         TestQuestionPanel fromRadio;
         public UpdateDataFields( JTextArea msgout ) {     // 100
              msg = msgout;
          }       // 100
         public void actionPerformed(ActionEvent evt) {     // 200
              String command = evt.getActionCommand();
              String reset = "Test of reset.";
              try{
                   if (command.equals("TestMe")){     // 300
                        msg.append("\nSuccessful");
                        Interface.changeCards();
                        }     // 300
              catch(Exception e){
                   e.printStackTrace();
              try{
                   if (command.equals("ButtonA")){     // 300
    // WHEN I CALL BOTH OF THE FOLLOWING METHODS THE DISPLAY WORKS
    // BUT THE CHANGECARDS METHOD DOES NOT WORK.  WHEN I COMMENT OUT
    // THE CALL TO THE DISPLAYMESSAGE METHOD THEN THE CHANGECARDS WORKS
    // FINE.  PLEASE THE INTERFACE CLASS NEXT.
                        Interface.changeCards();
                        Interface.displayMessage("test of xyz");
                        }     // 300
              catch(Exception e){
                   e.printStackTrace();
         }     // 200
    }     // 400
    // END OF UPDATEDATAFIELS  END END END
    public class Interface extends JFrame {     // 300
         static JPanel frameForCardPane;
         static CardLayout cardPane;
         static JTextArea msgout;
         TestQuestionPanel radio;
         Interface () {     // 100
              super("This is a JFrame");
            setSize(800, 400);  // width, height
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // set-up card layout
              cardPane = new CardLayout();
              frameForCardPane = new JPanel();     // for CardLayout
              frameForCardPane.setLayout(cardPane);     // set the layout to cardPane = CardLayout
              TestQuestionPanel cardOne = new TestQuestionPanel("ABC", "DEF", msgout, radio);
              TestQuestionPanel cardTwo = new TestQuestionPanel("GHI", "JKL", msgout, radio);
              frameForCardPane.add(cardOne, "first");
              frameForCardPane.add(cardTwo, "second");
              // end set-up card layout
              // set-up main pane
              // declare components
              msgout = new JTextArea( 8, 40 );
              ButtonPanel commandButtons = new ButtonPanel(msgout);
              JPanel pane = new JPanel();
              pane.setLayout(new GridLayout(2, 4, 5, 15));             pane.setBorder(BorderFactory.createEmptyBorder(30, 20, 10, 30));
              pane.add(frameForCardPane);
                 pane.add( new JScrollPane(msgout));
                 pane.add(commandButtons);
              msgout.append("Successful");
              setContentPane(pane);
              setVisible(true);
         }     // 100
    // HERE ARE THE METHODS THAT SHOULD HANDLE THE UPDATING
         static void changeCards() {     // 200
                   cardPane.next(frameForCardPane);
                   System.out.println("Calling methods works!");
         }     // 200
         static void displayMessage(String test) {     // 200
                   String reset = "Test of reset.";
                   String passMessage = test;
                   cardPane.next(frameForCardPane);
                   System.out.println("Calling methods works!");
                   msgout.append("\n"+ test);
         }     // 200
    }     // 300

    Hi,
    I instantiate it in this class. Does that change your opinion or the advice you gave me? Please help!
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class CardLayoutQuestionsv2 {
        public static void main(String[] arguments) {
            JFrame frame = new Interface();
            frame.show();
    }

  • Help to access a JTextArea created in another method ?

    Hello, first I am a new to java although i am a very experienced PHP programmer ... i am having trouble figuring out why i cannot access the JTextArea created inside BuildContainer() in my program below from another method NewFile().
    I am sure its just a scope issue or something along those lines, can someone please help with this and also explain to me whay it does not work and why something elese if offered will ?
    Ive hit a roadblock, and its driving me nuts.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*; 
    public class JEditor implements ActionListener {
         public static void main (String args[])
              JEditor Obj = new JEditor ();
              Obj.BuildGui ();
         public void actionPerformed(ActionEvent e)
         public void BuildGui ()
              JFrame WindowFrame = new JFrame("JEditor");
              JMenuBar WindowMenuBar = BuildMenuBar ();
              BuildContainer(WindowFrame.getContentPane());
              WindowFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              WindowFrame.setJMenuBar(WindowMenuBar);
              WindowFrame.pack();
              WindowFrame.setVisible(true);
         public JMenuBar BuildMenuBar ()
              Action Action_MenuNew = new Action_NewFile();
              Action Action_MenuOpen = new Action_OpenFile();
              Action Action_MenuSave = new Action_SaveFile();
              Action Action_MenuExit = new Action_Exit();
              JMenuBar Obj = new JMenuBar ();
              JMenu MenuObj = new JMenu("File");
              JMenuItem MenuItemNew = new JMenuItem(Action_MenuNew);
              JMenuItem MenuItemOpen = new JMenuItem(Action_MenuOpen);
              JMenuItem MenuItemSave = new JMenuItem(Action_MenuSave);
              JMenuItem MenuItemExit = new JMenuItem(Action_MenuExit);          
              MenuItemNew.setText("New");
              MenuItemOpen.setText("Open");
              MenuItemSave.setText("Save");
              MenuItemExit.setText("Exit");     
              MenuItemNew.addActionListener(this);
              MenuItemOpen.addActionListener(this);
              MenuItemSave.addActionListener(this);
              MenuItemExit.addActionListener(this);
              MenuObj.add(MenuItemNew);
              MenuObj.add(MenuItemOpen);
              MenuObj.add(MenuItemSave);
              MenuObj.addSeparator();
              MenuObj.add(MenuItemExit);
              Obj.add(MenuObj);
              return Obj;
         public JToolBar BuildToolBar ()
              Action Action_ButtonNew = new Action_NewFile();
              Action Action_ButtonOpen = new Action_OpenFile();
              Action Action_ButtonSave = new Action_SaveFile();
              JToolBar Obj = new JToolBar ();
              JButton ButtonNew = new JButton (Action_ButtonNew);
              JButton ButtonOpen = new JButton (Action_ButtonOpen);
              JButton ButtonSave = new JButton (Action_ButtonSave);
              ButtonNew.setIcon(new ImageIcon("IconNew.png", "New"));
              ButtonOpen.setIcon(new ImageIcon("IconOpen.png", "Open"));
              ButtonSave.setIcon(new ImageIcon("IconSave.png", "Save"));
              ButtonNew.setToolTipText("New file");
              ButtonOpen.setToolTipText("Open file");
              ButtonSave.setToolTipText("Save file");
              ButtonNew.addActionListener(this);
              ButtonOpen.addActionListener(this);
              ButtonSave.addActionListener(this);
              Obj.add(ButtonNew);
              Obj.add(ButtonOpen);
              Obj.add(ButtonSave);
              return Obj;
         public void BuildContainer (Container Obj)
              Obj.setLayout(new GridBagLayout());
              GridBagConstraints C = new GridBagConstraints();
              JToolBar ToolBar = BuildToolBar ();
              JTextArea FormTextArea = new JTextArea(10, 50);
              FormTextArea.setLineWrap(true);
              FormTextArea.setWrapStyleWord(true);
              JScrollPane FormScrollPane = new JScrollPane(FormTextArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
              C.gridx = 0;
              C.gridy = 0;
              Obj.add(ToolBar, C);
              C.gridx = 0;
              C.gridy = 1;
              Obj.add(FormScrollPane, C);
         public void NewFile ()
              // Problem is here ? Cannot access the textarea from here, not sure why ?
              FormTextArea.setText("test");
         public class Action_NewFile extends AbstractAction {
              public void actionPerformed(ActionEvent e)
                   NewFile ();
    };

    first I am a new to java You should learn the standard Java naming conventions. Basically variable names and method names should be mixed lower/upper case on each word:
    windowFrame -not WindowFrame
    buildMenuBar() - not BuildMenuBar()
    For class names you do upper case the the first character of each word.
    Your code is confusing to read since everything is upper cased and therefore looks like a reference to a class.

  • Can't update text in JTextArea! Can you help?

    [Update: If I remove the transparency everything is fine. However, I really need the transparency..]
    Hi,
    I have the simplest question, but I can't seem to get an answer to it. The problem is very simple: I have defined a JTextArea and I'm reading text into it. The problem is that the old text does not disappear, and the new text is pasted on top, making it unreadable. As an "act of desperation" I fixed this by setting the area invisible, updating it and setting it visible again, as you can see in the code. It works, but now it blinks in the screen (quite annoying!).
    Is there a smarter way to to this? I need this on a transparent window (see class init below), overlayed on another JFrame.
    I am on Mac OS X.
    I hope some of you can help me with this problem
    Thanks a lot in advance
    Lele
    public void UpdateOverlay(){
            try{
                BufferedReader b = this.ReadUrl("http://localhost/~"+System.getProperty("user.name")+"/overlaytext.txt");
                this.Overlay.setVisible(false);
                this.OverlayText.read(b, null);
                this.Overlay.setVisible(true);
            }catch(Exception e){
                e.printStackTrace();
        }Here you can see how I have initialized the class
    public class MyClass {
        //Overlay section
        public JFrame Overlay=new JFrame("Overlay");
        public Color OverlayColor=new Color(0.0f,0.0f,0.0f,0.0f);
        public JTextArea OverlayText=new JTextArea();
        public long Refresh_time=200;//ms
        /** Creates a new instance of MyClass */
        public MyClass(AWT1UpFrame f) {
            int width=270,height=170,border_x=20,border_y=20;
            //Initialize Overlay
            this.Overlay.setVisible(false);
            this.Overlay.setBackground(this.OverlayColor);
            this.Overlay.setLocationRelativeTo(null);
            this.Overlay.setUndecorated(true);
            this.Overlay.setSize(width,height);
            System.out.println("loc="+f.getLocation());
            int x = f.getLocation().x+border_x;
            int y = f.getLocation().y +f.getSize().height - border_y - height;
            this.Overlay.setLocation(x, y);
            this.Overlay.add(this.OverlayText);
            this.Overlay.setAlwaysOnTop(true);
            this.OverlayText.setLineWrap(true);
            this.OverlayText.setWrapStyleWord(true);
            this.OverlayText.setForeground(Color.GREEN);
            this.OverlayText.setBackground(this.OverlayColor);
            this.OverlayText.setFont(new Font("Arial", Font.ROMAN_BASELINE, 16));
    /* and so on*/Edited by: Lele on Oct 25, 2007 4:22 PM

    Hi, so this is the class. If I keep it like this, it simply overwrites old text with the new (like JTextArea thinks that the old text is a part of the background to be buffered). If I set it invisible and back to visible it works, but it blinks.
    How can I let JTextArea understand that it shouldn't consider the old window as a background? Should I use another class?
    Pls keep in mind that I'm on Mac, so maybe it's a Mac-specific thing, but I'd like to know..
    Thanks
    Lele
    package transparency;
    import java.net.*;
    import javax.swing.*;
    import javax.xml.parsers.*;
    import java.awt.*;
    import java.awt.font.*;
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    import java.util.List;
    import apple.awt.CTextArea;
    public class Overlay {
        //Overlay section
        public JFrame Overlay=new JFrame("Overlay");
        public Color OverlayColor=new Color(0.0f,0.0f,0.0f,0.0f);
        public JTextArea OverlayText=new JTextArea();
        public long Refresh_time=200;//ms
        /** Creates a new instance of Overlay */
        public Overlay() {
            int width=270,height=170,border_x=20,border_y=20;
            //Initialize Overlay
            this.Overlay.setVisible(false);
            this.Overlay.setBackground(this.OverlayColor);
            this.Overlay.setLocationRelativeTo(null);
            this.Overlay.setUndecorated(true);
            this.Overlay.setSize(width,height);
            //System.out.println("loc="+f.getLocation());
            //int x = f.getLocation().x+border_x;
            //int y = f.getLocation().y +f.getSize().height - border_y - height;
            //this.Overlay.setLocation(x, y);
            this.Overlay.add(this.OverlayText);
            this.Overlay.setAlwaysOnTop(true);
            this.OverlayText.setLineWrap(true);
            this.OverlayText.setWrapStyleWord(true);
            this.OverlayText.setForeground(Color.GREEN);
            this.OverlayText.setBackground(this.OverlayColor);
            this.OverlayText.setFont(new Font("Arial", Font.ROMAN_BASELINE, 16));
            this.Overlay.setVisible(true);
        public void UpdateOverlay(){
            try{
                //Reading URL
                //String Address="http://localhost/~"+System.getProperty("user.name")+"/overlaytext.txt";
                //URL url= new URL(Address);
                //BufferedReader b = new BufferedReader(new InputStreamReader(url.openStream()));
                //this.Overlay.setVisible(false);
                //this.OverlayText.read(b, null);
                //this.Overlay.setVisible(true);
                //Test
                //this.Overlay.setVisible(false);
                String RandomText="The time is: "+System.currentTimeMillis();
                this.OverlayText.setText(RandomText);
                //this.Overlay.setVisible(true);
            }catch(Exception e){
                e.printStackTrace();
    }.. and this is the main
    package transparency;
    import java.net.*;
    import javax.swing.*;
    import javax.xml.parsers.*;
    import java.awt.*;
    import java.awt.font.*;
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    import java.util.List;
    import transparency.*;
    public class Main {
        /** Creates a new instance of Main */
        public Main() {
        public static void main(String[] args) {
            JFrame f=new JFrame();
            f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
            f.setVisible(true);
            Overlay ov=new Overlay();
            try{
                while(f.isVisible()){
                    ov.UpdateOverlay();
                    Thread.sleep(100);
            }catch(Exception e){
                e.printStackTrace();
    }Edited by: Lele on Oct 26, 2007 3:40 AM

  • Help needed: Creating web link in JDialog Box

    I'm in need of this urgently, any help would be much appreciated. I'm currently display some information in a JDialog box when an item is clicked in a JApplet.
    I need to display a weblink within the dialog box.
    Thanks anyone

    I am using JDeveloper 10.1.3.3.0. Thanks Heaps

  • JTextArea need help in size

    Hello everyone. I have a quick question. When my program opens I have the window open to the max by getting the screen size dimension. I also have a text area in the frame that I would like do to the same. Any ideas? I have tried setRow, setCol but the problem is these will vary across computers. I tried textArea.setSize(dimension of screen) but this only accounts for the cols, not rows so it sizes the cols to the max but not the rows.

    Gotcha, ok I must be doing something wrong somewhere. Thanks for helping me out, I will post my code. Also, looking back at my code I was not using border layout so this may have been the problem. Can you take a peak though? It may be something else. I would basically like the text area to resize when the window does but always fill up all the space under the menu. If I can get this working I'm almost done since all the functionality works. I left out that code though to shorten this up some, I mainly added the code where I create and add the panel to the frame.
    This is the driver, basic creation of the frame
    import javax.swing.JFrame;
    import java.awt.*;
    public class Run {
      public static void main(String args[]) {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Notepad n = new Notepad();
        n.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        n.setSize(screenSize);
        n.setVisible(true);
    }Here is the panel where I store the text area
    I also use this class to handle operations on the text area such as reading/writing to disk etc. I left out the functionality code to keep it small and to the point.
    public class NotepadFile extends JPanel {
      private JTextArea mainTextArea;
      public NotepadFile( ) {
        setLayout(new FlowLayout()); //default 
        mainTextArea = new JTextArea();
        mainTextArea.setLineWrap(true);
        add(mainTextArea);     
    }Finally, here is where I add the panel to the main frame. Again, i'm leaving out the functionality code like event handlers and such.
    public class Notepad extends JFrame {
      private NotepadFile nFile;
      private final int fileMenuIndex = 0,
                  formatMenuIndex = 1,
                  helpMenuIndex = 2;
      public Notepad( ) {
        super("Notepad");
        JMenuBar mainMenuBar;
        JMenu menu[];
        nFile = new NotepadFile();
        mainMenuBar = new JMenuBar();
        setJMenuBar(mainMenuBar);
        menu = new JMenu[menuNames.length];
        for(int i=0;i<menuNames.length;i++) {
          menu[i] = new JMenu(menuNames); //create a menu
    menu[i].setMnemonic(menuMnemonic[i]);
    //here is where I created menu items but I cut it out here
    //continued..
    for(int i=0;i<menuNames.length;i++)
    mainMenuBar.add(menu[i]); //add menus to menu bar
    add(new JScrollPane(nFile));
    //here I also tried add(new JScrollPane(nFile), BorderLayout.CENTER); but it didn't work

Maybe you are looking for

  • SAP BusinessObject Mobile WebI Report Prompt Issue

    Hi, I have problem to view the Prompt value in Long Text for WebI report in my iPad. The SAP BusinessObject Mobile application is on version 5.1.12. We are using BI Platform 4.1, and the WebI report is connected to Bex Query using BICS connection. Be

  • How to find out Number of entries in a Huge Table?

    Hi, I would like to know Number of entries in table DFKKOP. when i try to get it through se16, it takes more than 10 minutes in dialogue process so a time out occurs. is there any way to find out number of entries in the table Apart from creating a p

  • How do I save markers?

    Ok for the life of me I can't understand how am I supposed to save markers in STP? I open an audio file then insert markers using "M" on my keyboard, I then click save and exit and when I come back the markers are gone? Is this a bad joke. Can someon

  • Using I web generated website as a storage for pics

    Is it possible to access the photos on my Iweb generated webpage to paste them ino an entry on a bulletin board? What i did on my yahoo account was to fill in the html on the image section of a bulletin board entry, and they would then show up in my

  • Schubert|it PDF Browser Plugin

    Is anyone able to have this plugin working with Safari in Snow Leopard? (OS 10.6.8, Safari 5.1.9). It works fine with Safari on my Tiger machines