JTextArea on JWindow

Why can't I make a JTextArea on JWindow uneditable?
Heres the code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Note extends JWindow {
JTextArea ta;
public static void main(String args[]) {
new Note();
public Note() {
ta = new JTextArea("j;lsa ;lasjfasdf asdf sadfsadfsad ;lkasdf ;lksa;lkfs;al fj;lksadfl; l;kslkfdf l");
ta.setLineWrap(true);
ta.setWrapStyleWord(true);
ta.setFont(new Font("Verdana",Font.BOLD,24));
ta.setEditable(true);
JScrollPane scrollPane = new JScrollPane(ta,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(scrollPane,BorderLayout.CENTER);
setSize(300, 300);
setVisible(true);
// Give focus for keystrokes
requestFocus();
but when I changed extends JWindow into extends JFrame, ta.setEditable(true) worked fine.
Please explain it to me. Thank you very much.

>
JWindow and focus: If you happen to use a JWindow in your GUI, you should know that the JWindow's owning frame must be visible for any components in the window to get the focus. By default, if you don't specify an owning frame for a JWindow, an invisible owning frame is created for it. The result is that components in JWindows might not be able to get the focus. The solution is to either specify a visible owning frame when creating the JWindow, or to use an undecorated JFrame instead of JWindow.
from:
http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html

Similar Messages

  • JTextArea in JWindow

    Basic problem is typing text in a JTextArea once added to JWindow, sounds simple?
    Once the textarea is added there's no caret displayed in the area, and does not accept focus.
    JWindow window = new .....
    JPanel panel = new ......
    panel.add(new JTextArea());
    window.add(panel);
    Is there a bug etc, or do other containers such as JFrame provide additional functionality to support textareas?

    See this thread:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=410638

  • JWindow JTextArea Issue... Help

    Hello guys and gals,
    I'm sure this issue I'm having is very common here to us programmers and people have asked this question several times.
    I'm using JWindow right now and I have a JTextArea that's not editable at all even though I've set it to be editable.. All I can do is setText to be there... It must be a bug or something..
    I will not convert to JFrame though it's easier to do so. JWindow is needed. Is it possible to my JTextArea editable so I can continue to program or am I just wasting time? Can anyone explain to me in simple terms to fix this issue? Maybe my code is incorrect.. Here's my entire code:
    import javax.swing.*;
    import javax.swing.border.EtchedBorder;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    public class JustToSee extends JWindow implements ActionListener
         Dimension screenSize =
            Toolkit.getDefaultToolkit().getScreenSize();              
         private JPanel background, outpassBox, inpassBox, wrongBox,
         passBoxoutSide, wrongBoxoutside, inwrongBox;
         private JButton exit;
         private JLabel wrongL, passL;
                         private JTextArea wrongT;
         public JustToSee()
              setBackground(Color.BLACK);
              Container pane = getContentPane();
              pane.setLayout(null);
              background = new JPanel();
              background.setSize(Toolkit.getDefaultToolkit().getScreenSize());
              background.setBackground(Color.black);
              background.setLayout(null);          
              outpassBox = new JPanel();
              outpassBox.setSize(650, 750);
              outpassBox.setLocation(600,30);
              outpassBox.setBackground(Color.black);
              outpassBox.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED, Color.black, Color.blue));
              outpassBox.setLayout(null);
              inpassBox = new JPanel();
              inpassBox.setSize(610,600);
              inpassBox.setLocation(20, 120);
              inpassBox.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED, Color.black, Color.blue));
              inpassBox.setBackground(Color.black);
              inpassBox.setLayout(null);
              wrongBox = new JPanel();
              wrongBox.setSize(300, 750);
              wrongBox.setLocation(50, 30);
              wrongBox.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED, Color.black, Color.blue));
              wrongBox.setBackground(Color.black);
              wrongBox.setLayout(null);
              passBoxoutSide = new JPanel();
              passBoxoutSide.setSize(610, 80);
              passBoxoutSide.setLocation(20,30);
              passBoxoutSide.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED,Color.black, Color.blue));
              passBoxoutSide.setBackground(Color.black);
              passBoxoutSide.setLayout(null);
              wrongBoxoutside = new JPanel();
              wrongBoxoutside.setSize(260, 80);
              wrongBoxoutside.setLocation(20, 30);
              wrongBoxoutside.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED,Color.black, Color.blue));     
              wrongBoxoutside.setBackground(Color.black);     
              wrongBoxoutside.setLayout(null);
              inwrongBox = new JPanel();
              inwrongBox.setSize(260, 600);
              inwrongBox.setLocation(20, 120);
              inwrongBox.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED,Color.black, Color.blue));
              inwrongBox.setBackground(Color.red);
              inwrongBox.setLayout(null);
              passL = new JLabel("Password Field...");
              passL.setForeground(Color.blue);
              passL.setFont(new Font("Computerfont", Font.BOLD, 24));
              passL.setSize(300, 60);
              passL.setLocation(10, 30);
              wrongL = new JLabel("Wrong Passwords...");
              wrongL.setForeground(Color.blue);
              wrongL.setFont(new Font("Computerfont", Font.BOLD, 24));
              wrongL.setSize(300, 60);
              wrongL.setLocation(10, 30);
              wrongT = new JTextArea(50, 1);//Inside the 2nd JPanel on the left side. It fills up the entire panel
              wrongT.setBackground(Color.white);
              wrongT.setForeground(Color.blue);
              wrongT.setFont(new Font("Computerfont", Font.BOLD, 18));
              wrongT.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED,Color.black, Color.blue));
              wrongT.setLocation(0,0);
              wrongT.setSize(260, 600);
              wrongT.setText("This is where the text goes! \nThis needs to be edited. Help =(");
              wrongT.setLineWrap(true);
              wrongT.setEditable(true);
              wrongT.setFocusable(true);
              exit = new JButton("EXIT");
              exit.setBackground(Color.black);
              exit.setForeground(Color.blue);
              exit.setFont(new Font("Computerfont",Font.BOLD,16));
              exit.setLocation(380, 100);
              exit.setSize(100, 60);
              exit.addActionListener(this);
              pane.add(background);
              background.add(exit);
              background.add(outpassBox);
              background.add(wrongBox);
              outpassBox.add(inpassBox);
              outpassBox.add(passBoxoutSide);
              passBoxoutSide.add(passL);
              wrongBox.add(wrongBoxoutside);
              wrongBox.add(wrongT);          
              wrongBoxoutside.add(wrongL);
              wrongBox.add(inwrongBox);
              inwrongBox.add(wrongT);          
         public void actionPerformed(ActionEvent e)
              if(e.getSource() == exit)
                   System.exit(0);
         public static void main(String[] args)
         JustToSee w = new JustToSee();
         GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(w);
    }Your help is greatly appreciated... =) Take care.
    Gabriel Young

      public JustToSee()
        super(new JFrame(){public boolean isShowing(){return true;}});//<----------
        setBackground(Color.BLACK);

  • JTextArea broken in JWindow

    I can type in a JLabel that I add to a JFrame, but as soon as I use JWindow instead of JFrame, the JTextArea refuses to function.
    Any suggestions?

    Looking through the JWindow API docs, I found
    public JWindow()
    Creates a window with no specified owner. This window will not be focusable.
    I suppose the fact that the window cannot gain focus would have something to do with my problem. I have tried adding a mouse listener to my JTextArea and then having it requestFocus() on mouseClicked, but it didn't do anything to help solve my problem.... any ideas?

  • JTextField in a FullScreen JWindow jdk1.4

    I have a problem that must have a simple solution I hope.
    I have a JWindow wich I run in fullscreen mode, the contentPane of the JWindow contains a JPanel wich contains JButtons, JLabels and JTextFields I have no problem with the JButtons and JLabels, but the JTextFields get no cursor when clicked and it is therefore impossible to enter text into them.
    I tried using the same JPanel in an ordinary JFrame (not fullscreen) and it worked just as it should.
    What am I missing?
    The JPanel (shortened)
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import javax.swing.*;
    class TheMainMenuPanel extends JPanel
         private BufferedImage background;
         private Graphics2D g2;
         private JButton exitButton=new JButton("Exit Game");
         private JTextField portField=new JTextField(5);
         private JLabel portLabel=new JLabel("Port of game");
         public TheMainMenuPanel()
              Image tmp=new ImageIcon("Graphics\\MainMenuBack.gif").getImage();
              background=ImageUtilities.makeBufferedImage(tmp);
              exitButton.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        System.exit(0);
    add(portLabel);
         add(portField);
    add(exitButton);
         public void paintComponent(Graphics g)
              g2=(Graphics2D)g;
              g2.drawImage(background,0,0,null);
    I'd be happy for any answer

    I got the same problem with a JTextArea and a JWindow in fullscreen mode.
    How did you got in fullscreen with a JFrame?
    did you found an other solution?
    thanks for your help
    Thomas.

  • JViewport + JTextArea

    I am writing some code that will display a JTextArea in a JViewport just above a progress bar. The idea is for the last several lines of the progress to be visible on the screen. However, once I fill up the current JTextArea, I have not been able to scroll down as I add new information. I would like this to happen programmatically, so that the latest message is always displayed. I have tried using:
    textarea.scrollRectToVisible( rectangle );
    and this doesn't seem to work. When I use:
    viewport.viewport.setViewPosition( point );
    I cause the application to crash even when I am passing a point where there should be just enough component left to fill the viewport from that point. Would someone point me in the right direction on this issue?
    -Benjamin

    I think I may have discovered something else that is related to why I can't get this to work correctly. The screen that this update is taking place on is a JWindow with none of the standard borders, titlebars, or window controls of a standard JFrame. (It is a splash screen) When I try the following code:
    Point p = new Point(viewport.getViewPosition());
    p.y = textArea.getHeight();
    viewport.setViewPosition(p);
    I get this exception:
    java.lang.ClassCastException: java.awt.Window at
    javax.swing.JViewport.setViewPosition(JViewPort.java:1031)
    Is there some incompatibility between using this call in a JWindow?
    -Benjamin

  • JTextArea over JLabel(image for background) Can't Receive Mouse Events

    Hi, I use JLabel for putting background image to a JWindow. But when i put a JTextArea component, i can see and edit the contents but JtextArea only receives keyboard events. When i click on it ,its Focus Gained Event is not fired. No blinking cursor is shown.
    I tried to use JLayeredPane and put them on different layers but it doesn't solve the problem.
    I searched the Forums but can't find a suitable answer.
    Any comments please...

    hey man,
    your problem happen not because your JTextArea over a JLabel, but cause JWindow not take focuse before jdk1.4, so if you need to see your blinking cursor just replace your JWindow with a JFrame.
    for the JTExtArea focusing problem, u may refer to the sun bug forum there is a lot of work around.

  • Difference between JTextArea and TextArea

    hi,
    what the difference betwween the two lines:
    JTextArea area = new JTextArea (10,20);
    and
    TextArea t2 = new TextArea("compilation",4,30,TextArea.SCROLLBARS_BOTH);     
    and what means numbers 10,20 for these lignes.
    bes regards.
    jihen.

    The major difference between the two classes is that JTextArea is Swing based and TextArea is AWT based. JTextArea is more efficient. In AWT, each component established a peer in the OS (think of them as all being viewed as a window in the OS). So as far as the OS was concerned, a window was a window, a button was a window, text area was a window, etc.
    This is why you will often see AWT components referred to as heavy components. Swing components, on the other hand, are often referred to as lightweight components. This is because only the top level components are heavy. This means think like JFram, JWindow, etc. still establish a peer in the OS (so the OS sees them as windows). The other components in Swing (JButton, JTextArea, etc.) are actually drawn onto the top level component's peer.
    So, in AWT, if you created 1 Frame with 2 TextArea components and 1 Button, 4 peers would be created in the OS (lots of resources). In Swing, the same combination would result in 1 peer (for the JFrame). The 2 JTextArea compoonents and the JButton would simply be drawn graphically on the JFrame's peer (resulting in a significant resource saving).
    One last point; you'll notice the Swing components are named J+OldAWTName. So the AWT Button is JButton in Swing. Be sure never to mix the two typs. You most code all AWT or all Swing. Exceptions and Events are not included in this restriction since there is no "visual" representation of these classes (they are just basic JavaBean classes).
    Hope this gets you started.

  • JTextArea - setLineWrap(true) = no text

    Hi,
    Cross-posted to comp.lang.java.gui...
    I have a JTextArea that is running over a JPanel with an image in it.
    Here's the code:
    Image image = Toolkit.getDefaultToolkit().getImage("images/homer02.jpg");
    ImagePanel quotesPanel = new ImagePanel(image);
    quotesTextArea = new JTextArea(getNextQuote());
    quotesTextArea.setLineWrap(true);
    quotesTextArea.setWrapStyleWord(true);
    quotesTextArea.setOpaque(false);
    quotesPanel.add(quotesTextArea);
    When I try to use setLineWrap(true), the text won't display,
    but when that method is commented out, the text is displayed
    but centered and all on one line, falling off each end.
    Is there something I'm not doing? The code matches that in the TextComponent
    demo in the Swing tutorial, although they use a JFrame while this is all part of a
    JWindow that shows quotes from the ancient Greeks over an image of the poet
    Homer, (not Mr. Simpson). ImagePanel is an extension of JPanel that has an
    image as a background. getNextQuote() returns a quote from a text file.
    Thank you in advance,
    Edward

    hello Andy
    iam using the same and the text is visible. i.e textArea.setLineWrap( true );
    asrar

  • To refresh the contents in JTextArea on selection of a row in JTable.

    This is the block of code that i have tried :
    import java.awt.GridBagConstraints;
    import java.awt.SystemColor;
    import java.awt.event.ActionEvent;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.ListSelectionModel;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.table.DefaultTableModel;
    import ui.layouts.ComponentsBox;
    import ui.layouts.GridPanel;
    import ui.layouts.LayoutConstants;
    import util.ui.UIUtil;
    public class ElectronicJournal extends GridPanel {
         private boolean DEBUG = false;
         private boolean ALLOW_COLUMN_SELECTION = false;
    private boolean ALLOW_ROW_SELECTION = true;
         private GridPanel jGPanel = new GridPanel();
         private GridPanel jGPanel1 = new GridPanel();
         private GridPanel jGPanel2 = new GridPanel();
         DefaultTableModel model;
         private JLabel jLblTillNo = UIUtil.getHeaderLabel("TillNo :");
         private JLabel jLblTillNoData = UIUtil.getBodyLabel("TILL123");
         private JLabel jLblData = UIUtil.getBodyLabel("Detailed View");
         private JTextArea textArea = new JTextArea();
         private JScrollPane spTimeEntryView = new JScrollPane();
         private JScrollPane pan = new JScrollPane();
         String html= " Item Description: Price Change \n Old Price: 40.00 \n New Price: 50.00 \n Authorized By:USER1123 \n";
         private JButton jBtnExporttoExcel = UIUtil.getButton(85,
                   "Export to Excel - F2", "");
         final String[] colHeads = { "Task No", "Data", "User ID", "Date Time",
                   "Description" };
         final Object[][] data = {
                   { "1", "50.00", "USER123", "12/10/2006 05:30", "Price Change" },
                   { "2", "100.00", "USER234", "15/10/2006 03:30", "Price Change12345"},
         final String[] colHeads1 = {"Detailed View" };
         final Object[][] data1 = {
                   { "Task:Price Change", "\n"," Old Price:50.00"," \n ","New Price:100.00"," \n" }
         JTable jtblTimeEntry = new JTable(data, colHeads);
         JTable jTbl1 = new JTable(data1,colHeads1);
         ComponentsBox jpBoxButton = new ComponentsBox(LayoutConstants.X_AXIS);
         public ElectronicJournal() {
              super();
              jtblTimeEntry.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              if (ALLOW_ROW_SELECTION) { // true by default
    ListSelectionModel rowSM = jtblTimeEntry.getSelectionModel();
    rowSM.addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
    //Ignore extra messages.
    if (e.getValueIsAdjusting()) return;
    ListSelectionModel lsm = (ListSelectionModel)e.getSource();
    if (lsm.isSelectionEmpty()) {
    System.out.println("No rows are selected.");
    } else {
    int selectedRow = lsm.getMinSelectionIndex();
    System.out.println("Row " + selectedRow
    + " is now selected.");
    textArea.append("asd \n 123 \n");
    } else {
         jtblTimeEntry.setRowSelectionAllowed(false);
              if (DEBUG) {
                   jtblTimeEntry.addMouseListener(new MouseAdapter() {
         public void mouseClicked(MouseEvent e) {
         printDebugData(jtblTimeEntry);
              initialize();
         private void printDebugData(JTable table) {
    int numRows = table.getRowCount();
    int numCols = table.getColumnCount();
    javax.swing.table.TableModel model = table.getModel();
    System.out.println("Value of data: ");
    for (int i=0; i < numRows; i++) {
    System.out.print(" row " + i + ":");
    for (int j=0; j < numCols; j++) {
    System.out.print(" " + model.getValueAt(i, j));
    System.out.println();
    System.out.println("--------------------------");
         private void initialize() {
              this.setSize(680, 200);
              this.setBackground(java.awt.SystemColor.control);
              jBtnExporttoExcel.setBackground(SystemColor.control);
              ComponentsBox cmpRibbonHORZ = new ComponentsBox(LayoutConstants.X_AXIS);
              cmpRibbonHORZ.addComponent(jBtnExporttoExcel, false);
              jpBoxButton.add(cmpRibbonHORZ);
              this.addFilledComponent(jGPanel, 1, 1, 1, 1, GridBagConstraints.BOTH);
              this.addFilledComponent(jGPanel1, 2, 1, 11, 5, GridBagConstraints.BOTH);
              this.addFilledComponent(jGPanel2, 2, 13, 17, 5, GridBagConstraints.BOTH);
              jGPanel.setSize(650, 91);
              jGPanel.setBackground(SystemColor.control);
              jGPanel.addFilledComponent(jLblTillNo,1,1,GridBagConstraints.WEST);
              jGPanel.addFilledComponent(jLblTillNoData,1,10,GridBagConstraints.BOTH);
              jGPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,0,0,0));
              jGPanel1.setBackground(SystemColor.control);
              jGPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0,
                        0));
              spTimeEntryView.setViewportView(jtblTimeEntry);
              jGPanel1.addFilledComponent(spTimeEntryView, 1, 1, 11, 4,
                        GridBagConstraints.BOTH);
              jGPanel2.addFilledComponent(jLblData,1,1,GridBagConstraints.WEST);
              jGPanel2.setBackground(SystemColor.control);
              jGPanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0,
                        0));
              //textArea.setText(html);
              pan.setViewportView(textArea);
         int selectedRow = jTbl1.getSelectedRow();
              System.out.println("selectedRow ::" +selectedRow);
              int colCount = jTbl1.getColumnCount();
              System.out.println("colCount ::" +colCount);
              StringBuffer buf = new StringBuffer();
              System.out.println("Out Of For");
              /*for(int count =0;count<colCount;count++)
              {System.out.println("Inside For");
              buf.append(jTbl1.getValueAt(selectedRow,count));
              // method 1 : Constructs a new text area with the specified text. 
              textArea  =new JTextArea(buf.toString());
              //method 2 :To Append the given string to the text area's current text.   
             textArea.append(buf.toString());
              jGPanel2.addFilledComponent(pan,2,1,5,5,GridBagConstraints.BOTH);
              this.addAnchoredComponent(jpBoxButton, 7, 5, 11, 5,
                        GridBagConstraints.CENTER);
    This code displays the same data on the JTextArea everytime i select each row,but my requirement is ,it has to refresh and display different datas in the JTextArea accordingly,as i select each row.Please help.Its urgent.
    Message was edited by: Samyuktha
    Samyuktha

    Please help.Its urgentThen why didn't you use the formatting tags to make it easier for use to read the code?
    Because of the above I didn't take a close look at your code, but i would suggest you should be using a ListSelectionListener to be notified when a row is selected, then you just populate the text area.

  • How to Capture New Line in JTextArea?

    I apologize if this is easy, but I've been searching here and the web for a few hours with no results.
    I have a JTextArea on a form. I want to save the text to a database, including any newline characters - /n or /r/n - that were entered.
    If I just do a .getText for the component, I can do a System.println and see the carriage return. However, when I store and then retrieve from the database, I get the lines concatenated.
    How to I search for the newline character and then - for lack of a better idea - replace it with a \n or something similar?
    TIA!

    PerfectReign wrote:
    Okay, nevermind. I got it.
    I don't "see" the \n but it is there.
    I added a replaceAll function to the string to replace \n with
    and that saves to the database correctly.
    String tmpNotes = txtNotes.getText().replaceAll("\n", "<br />");Oh, you're viewing the text as HTML? That would have been good to know. ;)
    I'll have to find a Wintendo machine to try this as well.Be careful not to get a machine that that says "Nii!"

  • How to refresh a JPanel/JTextArea

    My main problem is that I don't know how to correctly refresh a JTextArea in an Applet. I have an Applet with 2 internal frames. Each frame is comprised of a JPanel.
    The first internal frame calls the second one as shown below:
    // Set an internal frame for Confirmation and import the Confirm class into it//
    Container CF = nextFrame.getContentPane();
    //<Jpanel>
    confirmation = new Confirmation( );
    CF.add ( confirmation, BorderLayout.CENTER );
    mFrameRef.jDesktopPane1.add(nextFrame,JLayeredPane.MODAL_LAYER);
    currentFrame.setVisible(false); // Hide this Frame
    nextFrame.setVisible(true); // Show Next Frame/Screen of Program
    confirmation (Jpanel) has a JTextArea in it. When it's called the first time it displays the correct information (based on choices from the first frame). If a user presses the back button (to return to first frame) and changes something, it doesn't refresh in the JTextArea when they call the confirmation(Jpanel) again. I used System.out.println (called right after jtextareas code), and it shows the info has indeed changed...I guess I don't know how to correctly refresh a JTextArea in an Applet. Here is the relevent code for the 2nd Internal Frame (confirmation jpanel):
    // Gather Info to display to user for confirmation //
    final JTextArea log = new JTextArea(10,35);
    log.setMargin(new Insets(5,5,5,5));
    log.setEditable(false);
    log.append("Name: " storeInfoRef.getFirstName() " "
    +storeInfoRef.getLastName() );
    log.append("\nTest Project: " +storeInfoRef.getTestProject() );
    JScrollPane logScrollPane = new JScrollPane(log);

    Here is the relevant code that I am having the problem with...
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    public class Confirmation extends JPanel {
    // Variables declaration
    private StoreInfo storeInfoRef; // Reference to StoreInfo
    private MFrame mFrameRef; // Reference to MFrame
    private Progress_Monitor pmd; // Ref. to Progress Monitor
    private JLabel ConfirmMessage; // Header Message
    private JButton PrevButton;                // Navigation Button btwn frames
    private JInternalFrame prevFrame, currentFrame; // Ref.to Frames
    // End of variables declaration
    public Confirmation(MFrame mFrame, StoreInfo storeInfo) {
    mFrameRef = mFrame; // Reference to MFrame
    storeInfoRef = storeInfo; // Reference to Store Info
    prevFrame = mFrameRef.FileChooserFrame; // Ref. to Previous Frame
    currentFrame = mFrameRef.ConfirmationFrame; // Ref. to this Frame
    initComponents();
    // GUI for this class //
    private void initComponents() {
    ConfirmMessage = new JLabel();
    PrevButton = new JButton();
    UploadButton = new JButton();
    setLayout(new GridBagLayout());
    GridBagConstraints gridBagConstraints1;
    ConfirmMessage.setText("Please confirm that the information "
    +"entered is correct");
    add(ConfirmMessage, gridBagConstraints1);
    // Gather Info to display to user for confirmation //
    final JTextArea log = new JTextArea(10,35);
    log.setMargin(new Insets(5,5,5,5));
    log.setEditable(false);
    log.append("Name: " storeInfoRef.getFirstName() " "
    +storeInfoRef.getLastName() );
    log.append("\nTest Project: " +storeInfoRef.getTestProject() );
    log.append("\nTest Director: " +storeInfoRef.getTestDirector() );
    log.append("\nTest Location: " +storeInfoRef.getTestLocation() );
    log.append("\nDate: " +storeInfoRef.getDate() );
    String fileOutput = "";
    Vector temp = new Vector( storeInfoRef.getFiles() );
    for ( int v=0; v < temp.size(); v++ )
    fileOutput += "\n " +temp.elementAt(v);  // Get File Names
    log.append("\nFile: " +fileOutput );
    // log.repaint();
    // log.validate();
    // log.revalidate();
    JScrollPane logScrollPane = new JScrollPane(log);
    System.out.println("Name: " storeInfoRef.getFirstName() " " +storeInfoRef.getLastName() );
    System.out.println("Test Project: " +storeInfoRef.getTestProject() );
    System.out.println("Test Director: " +storeInfoRef.getTestDirector() );
    System.out.println("Test Location: " +storeInfoRef.getTestLocation() );
    System.out.println("Date: " +storeInfoRef.getDate() );
    System.out.println("File: " +fileOutput );
    // End of Gather Info //
    add(logScrollPane, gridBagConstraints1);
    PrevButton.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(java.awt.event.MouseEvent evt) {
    PrevButtonMouseClicked(evt);
    PrevButton.setText("Back");
    JPanel Buttons = new JPanel();
    Buttons.add(PrevButton);
    add(Buttons, gridBagConstraints1);
    // If User Presses 'Prev' Button //
    private void PrevButtonMouseClicked(java.awt.event.MouseEvent evt) {
    try
    currentFrame.setVisible(false); // Hide this Frame
    prevFrame.setVisible(true); // Show Next Frame/Screen of Program
    catch ( Throwable e ) // If A Miscellaneous Error
    System.err.println( e.getMessage() );
    e.printStackTrace( System.err );
    }// End of Confirmation class

  • How to put a Jpanel always over a JtextArea ?

    I want to have a little Jpanel above a JTextArea.
    At the initialize section, I add first the Jpanel and after the JtextArea (both in a 'parent' Jpanel with null layout)
    When I run the program I see the Jpanel over the JtextArea, but when I write on it and it reaches the area when the Jpanel is placed, the JtexArea brings to front and the Jpanel is no longer visible.
    So, how can I have my Jpanel on top always ?
    And another question , is there a hierarchy that control that I Jpanel is always over a Jbutton (even if the initial z-order of the button is higher than the Jpanel's)
    Thanks
    ( I do not send any code because it is so simple as putting this two components into a Jpanel)

    tonnot wrote:
    And another question , is there a hierarchy that control that I Jpanel is always over a Jbutton (even if the initial z-order of the button is higher than the Jpanel's)JLayeredPane
    ( I do not send any code because it is so simple as putting this two components into a Jpanel)Try it with a JLayeredPane and if you still have problems, post a [SSCCE (Short, Self Contained, Compilable and Executable, Example Program)|http://mindprod.com/jgloss/sscce.html].
    db

  • How to repaint a JTextArea inside a JScrollPane

    I am trying to show some messages (during a action event generated process) appending some text into a JTextArea that is inside a JScrollPane, the problem appears when the Scroll starts and the text appended remains hidden until the event is completely dispatched.
    The following code doesnt run correctly.
    ((JTextArea)Destino).append('\n' + Mens);
    Destino.revalidate();
    Destino.paint(Destino.getGraphics());
    I tried also:
    Destino.repaint();
    Thanks a lot in advance

    Correct me if I am wrong but I think you are saying that you are calling a method and the scrollpane won't repaint until the method returns.
    If that is so, you need to use threads in order to achieve the effect you are looking for. Check out the Model-View-Contoller pattern also.

  • 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.

Maybe you are looking for

  • How do i find my ipod that has NO battery?

    I had been studying for some tests i had and doing homework and i had no time to charge my ipod 5g. Its dead so there is no wifi or gps or anything like that. I was wondering if there is an app to find it and that i did not have to install beforehand

  • Cover Art Doesn't Display for New CDs, Podcasts, etc.

    Cover art doesn't display for new items that I add to my 60GB iPod from iTunes. Older items are fine but new CDs, podcasts or songs purchased from iTunes don't display cover art on my iPod. The cover art is there when viewed in iTunes but just doesn'

  • CUA Issue

    Hi ! We have this user SAP_WSRT in our PI system. Our PI system is connected to CUA. This particular user has somehow been created as a local user in PI & refuses to move to CUA (even after deleting & re-connecting CUA). SCUG does not show this user

  • SQL Query for Database Connections

    What would be the proper syntax or DBA table to query and find out how many database connections there are currently? Thanks for all of your help!! Marlan

  • .tmp files in my itunes subdirectory

    I have several (over 200!) iT.xxx.tmp files in my iTunes repertory. Apparently they were created the same day. They are quite large and take loads of disk space. Does someone know why they were generated? Can I get rid of them without pain? Is there