How to for JTextField and JButton..

How can i set the size of the JTextField and getting the words alignment to be in Center format?? Can i use JButton, click on it and key in value to be displayed in text form?

Hi,
you can change the alignment really simple:
JTextField textField = new JTextField("Your Text");
textField.setHorizontalAlignment(JTextField.LEFT);
textField.setHorizontalAlignment(JTextField.CENTER);
textField.setHorizontalAlignment(JTextField.RIGHT);The size can be set by
setPrefferedSize(int w, int h)or try
setColumns(int columns)L.P.

Similar Messages

  • How to put JTextfield and JButton in a cell of JTable

    I'm trying to put two Components into one cell of a JTable. This is no
    problem (in the TableCellRenderer) unless it comes to editing in these
    cells. I have written my own CellEditor for the table.but there is one
    minor problem: Neither the JTextfield nor the JButton has the focus so I
    can't make any input! Does anybody know what's wrong, please help me for this issue ,plese urgent

    Here you go
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.AbstractCellEditor;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JTextField;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableCellEditor;
    public class TableEdit extends JFrame
         JTable table = new JTable();
         private String[] columnNames = {"non-edit1", "edit", "non-edit2"};
         public TableEdit()
              super("Table Edit");
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              createGUI();
              setLocationRelativeTo(null);
              setSize(400, 300);
              setVisible(true);
         private void createGUI()
              table.setModel(new DefaultTableModel(3,3)
                   public int getColumnCount()
                        return 3;
                   public boolean isCellEditable(int row, int column)
                        if(column == 1)
                             return true;
                        return false;
                   public String getColumnName(int column)
                        return columnNames[column];
                   public int getRowCount()
                        return 3;
                   public Class getColumnClass(int column)
                        return String.class;
                   public Object getValueAt(int row, int column)
                        return row + "" + column;
              table.setRowHeight(20);
              table.setDefaultEditor(String.class, new MyTableEditor());
              JScrollPane sp = new JScrollPane(table);
              add(sp);
         public class MyTableEditor extends AbstractCellEditor
         implements TableCellEditor
              JPanel jp = new JPanel(new BorderLayout(5,5));
              JTextField tf = new JTextField();
              JButton btn = new JButton("...");
              public MyTableEditor()
                   jp.add(tf);
                   jp.add(btn, BorderLayout.EAST);
                   btn.addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent e)
                             JOptionPane.showMessageDialog(null, "Clicked Lookup");
              public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
                   tf.setText(String.valueOf(value));
                   return jp;
              public Object getCellEditorValue()
                   return tf.getText();
         public static void main(String[] parms)
              new TableEdit();
    }

  • How Long For Fixing and Release WPA/WPA2 on N900?

    Hay Nokia!!
    I use N900 Maemo PR1.2 Lasted update.
    At home i'm create WPA2-Shared-key (Belkin Router) it's worked.
    At Friend Home i'm used WPA2-Shared-key (Belkin, Lynksys, D-Link) it's  worked no problem.
    At Office i can not used WPA2-Shared-key with Lynksys difference model it's not worked, but many co-worker worked with iPhone.
    and My Friend use iPhone 3Gs worked with all WPA2 - Shared Key that i'm try with N900.
    i try change MAC by macchanger it's a same Not worked.
    i'm asking for Maemo.org they toll me it's BUGS -_-"
    How long For Fixing and Release??

    you will not get a response as other then the mods,  nokia folks do not really watch this blog.   your best bet is the maemo community where you were before.
    maemo.org

  • JTextfield and JButton

    Hi all
    My problem is that i have a JTextfield that is connected to a Oracle database that allow the user to enter data in the database. I want to have a button that will allow the user to test to see whether the data entered in the textfield is valid.
    I'm not sure if i need to use sqlj or not. Any help would be gladly received.
    Thanks
    null

    Hmmm... lots and lots of ways to handle this, depending on your particular need for the particular type of 'validation'. ( More info? )
    "JTextField" is not connected to a database in the same way that the infoswing "TextFieldControl" is.. .therefore one could trap the event ActionPerformed off the JTextField and do the checks ( or use the jbutton like you suggest..but it would seem like you'd always want it checked and corrected before continuing towards the inevitable commit attempt??? ).
    You can use sqlj, or you can not use it... depends upon the way you've architected your application/environment and your needs and desires.
    Note (if you haven't already ) that you can also do a heck of a lot of validation at the entity/view object level.
    In my case ( an application ) I have a jdbc connection up at the front end for all my miscellaneous stuff, and a validate PL/SQL stored function. The nice things about using stored procedures/functions are that the validate routines can be nested for quick and easy use by triggers and stored procedures. If you put it outside the database it gets more fun should you want to get at the common validation routines from all approaches.
    Curious as to how other folk are architecting their validations....

  • JTextField and JButtons not appearing until clicked.

    I'm writing a program to refresh my CS1 java skills. For some reason when I try to add a JTextField and two JButtons to my container they don't appear until Ive clicked them.
    Actually more specifically, this only happens after a 100ms wait after setting the frame visible. Any less and the components wind up visible, but scrunched up in the top middle of my frame.
    Ive found that if I add the components before and after the wait they are visible and in the correct place, but this makes a noticeable flicker.
    I'm running windows vista if that matters.
    If someone could help me I would appreciate it.
    snippet of code:
    public scrollText()
         drawingThread.start();
         mainFrame.setSize(640,160);
         mainFrame.setContentPane(draw);
         mainPane = mainFrame.getContentPane();
         mainPane.setBackground(Color.white);
         mainFrame.setResizable(false);
         mainFrame.setVisible(true);
         try
              Thread.sleep(100);
              addInterface();
         catch(InterruptedException e){}
    public void addInterface()
         textInput.setBounds(1,103,501,31);
         play.setBounds(502,103,65,30);
         play.addActionListener(this);
         stop.setBounds(568,103,65,30);
         stop.addActionListener(this);
         mainPane.add(textInput);
         mainPane.add(play);
         mainPane.add(stop);
    }

    Postings can't be moved between forums. Now you know for the next time.
    The general form for building a GUI is
    frame.getContentPane().add( yourComponentsHere );
    frame.pack();
    frame.setVisible( true );Then all the compnoent will show up according to the rules of the layout managers used.
    However is you add components to the GUI "after" the GUI is visible then the components are not automatically painted. You need to tell the GUI to invoke the layout manager again so your code would be:
    frame.getContentPane().add( componentsToVisibleGUI );
    frame.getContentPane().validate();

  • About JtextField and JButton problem

    hi, I dont know how to make this, hope to get help:)
    I wanna like this:
    A JtextField object -- for user to input some Integer
    A JButton -- when users click the button, the content in JtextFiled will be delivered to a variable (say, int a, sent to this "a")in my program.
    Here, We dont need to check the content if it is Integer or not for simple.
    Any idea for me? thanks!

    Write a listener class that implements listener interface. in that class implement the actionPerformed method of the super interface as u need.( I.e assign the value to the variable). Then bind this class with ur button using addActionListener() method( look in API).
    ex:
    bottonName.addActionListener( new ActionListener()
              public void actionPerformed(ActionEvent e)
                   var = textarea.val;
         });

  • How value for PR00 and VPRS is calculated?

    Hi Everybody,
    Can anyone answer me the below mentioned question....
    1.Standard price in material in a/c view which comes in Pricing procedure as VPRS..............is that manufacturing cost(COGM)? Does it come from production?
    2.We calculate profit comparing standard price(VPRS) with the price which we get after deducting all the discounts and adding all taxes and freght.How do we fix up or determine base price(PR00)?Is it COGS?Who actually give or decide PR00 price in any Organization?
    3.Dfference between PR00 and VPRS.
    I wll really be grateful to get a clear picture of this.
    Thnx in advance.
    With regards,
    Subh

    Hi,
    PR00 - Basically this will be determined automatically during the sales order processing with the use of condition records
    PR00 indicates the basic price exclusive of any addition of discounts, taxes, etc.
    VPRS in requirement is 4,This pulls the condition type,and in item category we mention determine cost,With the help of this the cost of the material is dragged to the sales order
    VPRS is the condition which fetches the moving avg pricce of the material which gets determined by the invoice verification value for purchse orders. it may vary or be constant depending on the fact if its MAP or std price. these settings are in the material master acc./costing views. VPRS works for non-BOM scenarios. in BOM scenarios there is a cond called KUMU. kumu adds the costs of all the shild components to the header part. VPRS and KUMU form and exclusion grp i.e only once can be present in the sales order.
    Hope this helps you.
    Regards,
    Rakesh

  • How long for updates and bug fixes usually?

    I'm new to Logic and even new to Macs. I'm just wondering how long does it usually take for Apple to release bug fixes and updates to Logic?
    Also, how long did Apple take to get around to providing worthwhile updates to Logic 7? Were there substantial updates changed work flow, functionality, etc?
    Basically I'm wondering how long until Logic 8 will be more stable and complete?

    Logic 7 was never updated so as to provide any significant changes in workflow over its initial release. But apparently L7 so intrinsically broken that they abandoned any effort to fix it. Instead, they developed Logic 8.
    L8 has some very obvious bugs, yes. They need to be fixed yesterday. But as usual, Apple is dragging its feet in this regard.
    To your question, how long.... well, L7 updates occurred about every 4 months. There's no telling if they'll be on a more conscientious schedule for releasing L8 updates. They only offer end-users one choice: wait and see what happens.

  • How to print JTextPane containing JTextFields, JLabels and JButtons?

    Hi!
    I want to print a JTextPane that contains components like JTextFields, JLabels and JButtons but I do not know how to do this. I use the print-method that is available for JTextComponent since Java 1.6. My problem is that the text of JTextPane is printed but not the components.
    I wrote this small programm to demonstrate my problem:
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.print.PrinterException;
    public class TextPaneTest2 extends JFrame {
         private void insertStringInTextPane(String text,
                   StyledDocument doc) {
              try {
                   doc.insertString(doc.getLength(), text, new SimpleAttributeSet());
              catch (BadLocationException x) {
                   x.printStackTrace();
         private void insertTextFieldInTextPane(String text,
                   JTextPane tp) {
              JTextField tf = new JTextField(text);
              tp.setCaretPosition(tp.getDocument().getLength());
              tp.insertComponent(tf);
         private void insertButtonInTextPane(String text,
                   JTextPane tp) {
              JButton button = new JButton(text) {
                   public Dimension getMaximumSize() {
                        return this.getPreferredSize();
              tp.setCaretPosition(tp.getDocument().getLength());
              tp.insertComponent(button);
         private void insertLabelInTextPane(String text,
                   JTextPane tp) {
              JLabel label = new JLabel(text) {
                   public Dimension getMaximumSize() {
                        return this.getPreferredSize();
              tp.setCaretPosition(tp.getDocument().getLength());
              tp.insertComponent(label);
         public TextPaneTest2() {
              StyledDocument doc = new DefaultStyledDocument();
              StyledDocument printDoc = new DefaultStyledDocument();
              JTextPane tp = new JTextPane(doc);
              JTextPane printTp = new JTextPane(printDoc);
              this.insertStringInTextPane("Text ", doc);
              this.insertStringInTextPane("Text ", printDoc);
              this.insertTextFieldInTextPane("Field", tp);
              this.insertTextFieldInTextPane("Field", printTp);
              this.insertStringInTextPane(" Text ", doc);
              this.insertStringInTextPane(" Text ", printDoc);
              this.insertButtonInTextPane("Button", tp);
              this.insertButtonInTextPane("Button", printTp);
              this.insertStringInTextPane(" Text ", doc);
              this.insertStringInTextPane(" Text ", printDoc);
              this.insertLabelInTextPane("Label", tp);
              this.insertLabelInTextPane("Label", printTp);
              this.insertStringInTextPane(" Text Text", doc);
              this.insertStringInTextPane(" Text Text", printDoc);
              tp.setEditable(false);
              printTp.setEditable(false);
              this.getContentPane().add(tp);
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              this.setSize(400,400);
              this.setVisible(true);
              JOptionPane.showMessageDialog(tp, "Start printing");
              try {
                   tp.print();
              } catch (PrinterException e) {
                   e.printStackTrace();
              try {
                   printTp.print();
              } catch (PrinterException e) {
                   e.printStackTrace();
         public static void main(String[] args) {
              new TextPaneTest2();
    }First the components are shown correctly in JTextPane, but when printing is started they vanish. So I created another textPane just for printing. But this does not work either. The components are not printed. Does anybody know how to solve this?
    Thanks!

    I do not know how I should try printComponent. From the API-Doc of JComponent of printComponent: This is invoked during a printing operation. This is implemented to invoke paintComponent on the component. Override this if you wish to add special painting behavior when printing. The method print() in JTextComponent is completely different, it starts the print-job. I do not understand how to try printComponent. It won't start a print-job.

  • How can I put validation for JTextField when gotfocus and lostfocus

    Hi,
    How can I put validation for JTextField when gotfocus and lostfocus ?
    Thanks
    Wilson

    You add a focusListener to the control you wish to monitor. In the focusLost() handler you do whatever, in the focusGained() handler you do whatever.

  • Set specific size for JTextfield/Jbutton in BorderLayout?

    can some one tell me how to set a specific size for JTextfield/JButton in Border/BoxLayout please?
    I stried setSize, setPrefersize, setMAxsize, setMinsize, setBounds... but it won't work?
    For example. If I add a jbutton to a jpanel, which has borderlayout, it will take up ALL the space in that jpanel.
    Thanks

    Typically you use a BorderLayout for the high level layout and then add panels using other layouts to the BorderLayout. So for example on a simple dialog that is using a form that asks your for your first name and last name you would build a panel with those fields and add that panel to the center of the BorderLayout. Then you would create another panel for the "Ok" and "Cancel" buttons which would typically use a FlowLayout. Then you add that panel to the South of the BorderLayout.
    The Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html]How to Use LayoutManagers has all the information you need to know on using layout managers.

  • How can i use RTFEditorKit for JTextField.

    hi all,
    how can i use RTFEditorKit for JTextField.
    thanks in advance
    daya

    Don't cross post. This is a Swing related question and you have already posted in the Swing forum:
    http://forum.java.sun.com/thread.jspa?threadID=619619&tstart=0

  • Key and action binding for JTextField

    when JtextField is focused I need to bind a combined key command to execute a function. For example when user presses ctrl+n and action will be executed. How can I do this for JTextField?

    Use following method:
    public void addKeyBoardAction(JComponent comp, String name, KeyStroke keyStroke,
                                      Action action) {
            comp.getInputMap(JComponent.WHEN_FOCUSED).put(keyStroke, name);
            comp.getActionMap().put(name, action);
        }Call the method as:
    JTextField text=new JTextField();
    addKeyBoardAction(text, "MyTask", KeyStroke.getKeyStroke(
         KeyEvent.VK_SPACE,
         KeyEvent.CTRL_MASK), new MyAction());Thanks,
    Mrityunjoy
    Edited by: mrityunjoy on 17 Mar, 2009 6:40 PM

  • I have an ipad 2 and want to have one account for home and another for work, how do i do this?

    I have an Ipad 2 and use it for work, I want to run a second account for home, how do I do this?

    What kind of accounts? Multiple email accounts are supported.
    Multiple user accounts are not.
    If you are saying you would like to have one set of apps, media, etc
    for work and a different set for home, and switch between the 2
    depending on network login or location, this is not a feature of iOS.
    If this is not what you are asking, please post more details so someone
    may offer a solution.

  • How do you use one apple id for iPad and iphone

    We have an iPad, four iphone 3gs and a new iphone4.  We use one apple Id for each with iCloud.  Do we need a new apple Id for the 4gs?  Also how do we share the iPad between the iPhones for music & apps.   Thanks.

    To allow you to Message one another and FaceTimne one another see:
    MacMost Now 653: Setting Up Multiple iOS Devices For Messages and FaceTime

Maybe you are looking for

  • Detall with the configuration in cluster of my system PI

    Hello people We have  installed PI in cluster of microsoft 2003 and one application server with  this configuration, sometimes presents  problem with interfaces with status http_status_not_ok and with the load of the interfaces is slow. We tested a s

  • Urgant :where clause

    How we can use set_block_property built in to change where clause on pre-query trigger .I tried the following but it didn't work: set_block_property('DEPT',WHERE_CLAUSE,'DNAME LIKE ''C%'''); Any help would by appreciated .

  • Problem with updating my iPhotos.

    Ever since updating to the Maverick I have this issue. It keeps telling me that 'this update is for an app downloaded with a different Apple ID'. I don't have any other Apple ID except for the one I use and no one else has one in my household since I

  • Creating jar file for entity bean

    I am trying to deploy an entity bean..i compiled all the java files and created a dir by name META_INF and copied ejb-jar.xml and the other two .xml files which are needed to this dir. then using ,ant i tried to create the jar file ,,but it is giving

  • Need better reception with WRT54GS

    I just purchased a WRT54GS Wireless Router. I am very disappointed in it's range. It get low signal upstairs in my house making wireless connection very poor to non existence. My question is: is there a antenna booster or bigger antenna that I can pu