How can I display JTextFields correctly on a JPanel using GridBagLayout?

I had some inputfields on a JPanel using the boxLayout. All was ok. Then I decided to change the panellayout to GridBagLayout. The JLabel fields are displayed correctly but the JTextField aren't. They are at the JPanel but have a size of 0??? So we cannot see what we type in these fields... Even when I put some text in the field before putting it on the panel.
How can I display JTextFields correctly on a JPanel using GridBagLayout?
here is a shortcut of my code:
private Dimension sFieldSize10 = new Dimension(80, 20);
// Create and instantiate Selection Fields
private JLabel lSearchAbrText = new JLabel();
private JTextField searchAbrText = new JTextField();
// Set properties for SelectionFields
lSearchAbrNumber.setText("ABR Number (0-9999999):");
searchAbrNumber.setText("");
searchAbrNumber.createToolTip();
searchAbrNumber.setToolTipText("enter the AbrNumber.");
searchAbrNumber.setPreferredSize(sFieldSize10);
searchAbrNumber.setMaximumSize(sFieldSize10);
public void createViewSubsetPanel() {
pSubset = new JPanel();
// Set layout
pSubset.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
// Add Fields
gbc.gridy = 0;
gbc.gridx = GridBagConstraints.RELATIVE;
pSubset.add(lSearchAbrNumber, gbc);
// also tried inserting this statement
// searchAbrNumber.setText("0000000");
// without success
pSubset.add(searchAbrNumber,gbc);
pSubset.add(lSearchAbrText, gbc);
pSubset.add(searchAbrText, gbc);
gbc.gridy = 1;
pSubset.add(lSearchClassCode, gbc);
pSubset.add(searchClassCode, gbc);
pSubset.add(butSearch, gbc);
}

import java.awt.*;
import java.awt.event.*;
import javax .swing.*;
public class GridBagDemo {
  public static void main(String[] args) {
    JLabel
      labelOne   = new JLabel("Label One"),
      labelTwo   = new JLabel("Label Two"),
      labelThree = new JLabel("Label Three"),
      labelFour  = new JLabel("Label Four");
    JLabel[] labels = {
      labelOne, labelTwo, labelThree, labelFour
    JTextField
      tfOne   = new JTextField(),
      tfTwo   = new JTextField(),
      tfThree = new JTextField(),
      tfFour  = new JTextField();
    JTextField[] fields = {
      tfOne, tfTwo, tfThree, tfFour
    Dimension
      labelSize = new Dimension(125,20),
      fieldSize = new Dimension(150,20);
    for(int i = 0; i < labels.length; i++) {
      labels.setPreferredSize(labelSize);
labels[i].setHorizontalAlignment(JLabel.RIGHT);
fields[i].setPreferredSize(fieldSize);
GridBagLayout gridbag = new GridBagLayout();
JPanel panel = new JPanel(gridbag);
GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.insets = new Insets(5,5,5,5);
panel.add(labelOne, gbc);
panel.add(tfOne, gbc);
gbc.gridwidth = gbc.RELATIVE;
panel.add(labelTwo, gbc);
gbc.gridwidth = gbc.REMAINDER;
panel.add(tfTwo, gbc);
gbc.gridwidth = 1;
panel.add(labelThree, gbc);
panel.add(tfThree, gbc);
gbc.gridwidth = gbc.RELATIVE;
panel.add(labelFour, gbc);
gbc.gridwidth = gbc.REMAINDER;
panel.add(tfFour, gbc);
final JButton
smallerButton = new JButton("smaller"),
biggerButton = new JButton("wider");
final JFrame f = new JFrame();
ActionListener l = new ActionListener() {
final int DELTA_X = 25;
int oldWidth, newWidth;
public void actionPerformed(ActionEvent e) {
JButton button = (JButton)e.getSource();
oldWidth = f.getSize().width;
if(button == smallerButton)
newWidth = oldWidth - DELTA_X;
if(button == biggerButton)
newWidth = oldWidth + DELTA_X;
f.setSize(new Dimension(newWidth, f.getSize().height));
f.validate();
smallerButton.addActionListener(l);
biggerButton.addActionListener(l);
JPanel southPanel = new JPanel(gridbag);
gbc.gridwidth = gbc.RELATIVE;
southPanel.add(smallerButton, gbc);
gbc.gridwidth = gbc.REMAINDER;
southPanel.add(biggerButton, gbc);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(panel);
f.getContentPane().add(southPanel, "South");
f.pack();
f.setLocation(200,200);
f.setVisible(true);

Similar Messages

  • How can I display the correct enum ring value from a parameter file?

    A user will make selections based on the menu ring (there are several of these) and then the values are saved for later use as a parameter (text) file. I have several menu rings which I write out to a parameter (text) file.
    How can I take these text values back into the appropriate location in the menu ring. For example, if I have menuring_value at index 0, menuring_value at index 1, etc. how do I make sure that, when the par (text) file is loaded, the saved values are the ones displayed without erasing the displayed menu ring value and inputting the saved one (from the parameter file). I would like the text value to search the appropriate menu ring, make a match and then display that menu ring value when the parameter file is loaded.

    If I understand your question, attached VI should have solved your doubt
    In this example, Configuration File VIs are used to save & retrieve MenuRings' statuses.
    As this VI is improvised, please further modify it to suit your needs.
    Cheers!
    Ian F
    Since LabVIEW 5.1... 7.1.1... 2009, 2010
    依恩与LabVIEW
    LVVILIB.blogspot.com
    Attachments:
    GUI_Menu Ring Status Save & Retrieve.vi ‏69 KB

  • How can I display summary for every 15 minutes using DATE datatype

    This is probably an easy question, but the answer eludes me...
    I am trying to write a SQL report that displays aggregate totals for every 15 minute period. I know you can do something like this to get every minute:
    select to_char(import_date,'MM-DD-YYYY HH24:MI'),
    count(*) from
    package_ingest
    group by to_char(import_date,'MM-DD-YYYY HH24:MI')
    But how can I change this query so that I get every 15 minutes?
    Any feedback is greatly apprecaited!
    Thanks,
    -ADK

    Hi,
    GROUP BY  TRUNC (SYSDATE) + FLOOR ( (import_date - TRUNC (SYSDATE))
                                          * 24
                            * 4
                            )SYSDATE is an arbitrary reference point. It doesn't matter if import_date is earlier or later (or sometimes earlier and sometimes later).
    If you want to display this in the SELECT clause, or use it in the ORDER BY clause, then repeat the expression there, or compute it once in a sub-query.
    WITH  got_i_d_15     AS
         SELECT     TRUNC (SYSDATE) + FLOOR ( (import_date - TRUNC (SYSDATE))
                                               * 24
                                 * 4
                                 ) AS i_d_15
         FROM     package_ingest
    --     WHERE     ...          -- If needed
    SELECT       TO_CHAR (i_d_15, 'MM-DD-YYYY HH24:MI')     AS import_date
    ,       COUNT (*)                               AS cnt
    FROM       got_i_d_15
    GROUP BY  i_d_15
    ORDER BY  i_d_15;

  • How can i display Waveform chart in a subpanel using Vi templates.

    Hi All
    I am new to Labview hence need  some help. I am trying to develop an application which reads some data from a Wireless Sensor Network (WSN). The WSN consists of base station connected to the USB port which recieves data from other sensor nodes.  The data comes in a certain format.  Node name, temperature reading, humidity reading etc. I want to read the data from the serial port and  based on the Node name, i want to display the information for each node in s separate window or subpanel etc. So if a new node is detected then a new window is created for that node. Since all the nodes have the same sensors on board i only need a one template. I can read the data using the serial port, parse the data to detect which node it is and also what the sensor readings are. I have created a template VI for the sensor node. I am having problems in displaying the template VIs in a subpanel. I can succesfully display a Waveform graph in the subpanel but i am having problems in displaying a waveform chart in the subpanel. I can see the actual waveform chart in the subpanel, but i cannot see the plot. Would be greatful if someone could point out what i am doing wrong here.
    Many Thanks
    Raza
    Solved!
    Go to Solution.
    Attachments:
    template_graph.vi ‏16 KB
    graph_template.vit ‏11 KB

    Hi All
    I think i have solved the problem. It seems like i was running the Vi in a loop. I have taken the Run Vi outside the while lopp and this works fine. Also i need to close the reference at the end.
    Raza

  • How can I display the first and last name using a paramater as employee ID?

    Hi SAP,
    I have a parameter that is called {? Employee ID}.   What I want to do is display the first and last name based on the employee ID value entered in {? Employee ID} in the page header of the report.  Right now, when I put the following formula in the page header only some pages get the right result while other pages dont....
    if table.employeeid = {? Employee ID} then
    table.firstname" "table.lastname
    It appears as though if the first record in the details section on the beginning of each page happens to be the employee under {? Employee ID} then it prints it correctly, if it isn't I get a null value in the page header.
    Anyone have any ideas?
    Z

    Hi Try this,
    Whileprintingrecords;
    if ={?EmpID} then
    Also check the option "Default values for null" in the formula editor.
    Regards,
    Vinay

  • How can I display my macbook to ipad(s) using mirroring

    There are plenty of times when I want to show the people in a meeting what i'm looking at or doing on my laptop. If they have an ipad, is there a way to "mirror" my macbook to their ipad(s) directly without signing in to skype/google+/any other video sharing and sharing my screen?
    I saw the app reflection, but that goes the other way.
    Thanks!

    You can't. You can order replacement discs from Apple provided your model is not considered obsolete. You can also buy a copy of Snow Leopard:
    You can purchase Snow Leopard through the Apple Store: Mac OS X 10.6 Snow Leopard - Apple Store (U.S.). The price is $19.99 plus tax. You will be sent physical media by mail after placing your order.
    After you install Snow Leopard you will have to download and install the Mac OS X 10.6.8 Update Combo v1.1 to update Snow Leopard to 10.6.8.

  • How can I display date+time and not the point number in excell?

    Hi everyone,
    Could anybody tell me how I can save date + time to a file, so that  I can display on a diagram(excel) : date+time in (ox) and data (oy)? :
    My program sets in (ox) the point number and not the date+time....( although  date and time are written correctly in the column...)
    Any help would be great,
    Thanks,
    regards,
    Marc

    hi there,
    excel uses 01.01.1900 00:00 as the time offset, LabVIEW uses 01.01.1904 02:00, so you can't display the correct datetime in excel when you write the time as a fractional number of seconds from LabVIEW. you must format the datetime in LabVIEW to a string and write that to the column. use the "Format Date/Time String" - function and for example "%d.%m.%Y %H:%M:%S%3u" as the format string (see the functions help for more examples). you also could format your data to a string using "Format Into String" - function and write the file as a 2D string array. the decimal point you have to use depends on your system and its settings, but you can specify the decimal point in the Format string like "%.;%f" (means fractional number with point as decimal point).
    best regards
    chris 
    Best regards
    chris
    CL(A)Dly bending G-Force with LabVIEW
    famous last words: "oh my god, it is full of stars!"

  • How can I display iPad on tv via apple tv.

    How can I display screen from iPad using apple tv?

    The correct answer is only with a limited number of apps, you cannot share the iPad screen, unfortunately. YouTube, iPhoto. I am very disappointed keynote presentations are not supported.

  • How can  i  display the Number  instead of  E

    Hello Everyone ;
    I am getting confused. How can i display the Number but the Exponential value is coming as E.
    SQL> select sum(amount_sold) from sales;
    SUM(AMOUNT_SOLD)
    1.1287E+11
    Table details ..
    SQL> desc sales
    Name                                          Null?        Type
    AMOUNT_SOLD NUMBER
    i want to change 1.1287E+11 to "numeric"
    DB : 10.2.0.4
    os : rhel 5.1

    Just a minor correction on an obvious math/responding too fast error: 1.1287E+11 is a 12 digit number. You move the decimal 11 positions to the right which would add 7 zeroes to the value.
    MPOWEL01> l
      1  select length(to_char(1.1287E+11)), to_char(1.1287E+11,'999,999,999,999'), 1.1287E+11 "TEST"
      2* from sys.dual
    MPOWEL01> col TEST format 999999999999
    MPOWEL01> /
    LENGTH(TO_CHAR(1.1287E+11)) TO_CHAR(1.1287E+          TEST
                             12  112,870,000,000  112870000000the problem was that the OP failed to alias the sum result to the formatted column rather than the lenght of the data.
    HTH -- Mark D Powell --

  • Webdynpro ABAP - ALV how can i display Total of Column

    Hi friends,
    Webdynpro ABAP - ALV how can i display Total of Columns.
    Please tell me any metod is there or any solution.
    Thanks,
    Kumar.

    Hi
    You can take help of following code snippet to create totals for a particular column
    Data: lr_function_settings TYPE REF TO CL_SALV_WD_CONFIG_TABLE.
      DATA: lr_column_settings TYPE REF TO if_salv_wd_column_settings,
            lr_column          TYPE REF TO cl_salv_wd_column,
            lt_column type salv_wd_t_column_ref,
            ls_column type salv_wd_s_column_ref.
    Data:  lr_field_amnt type REF TO CL_SALV_WD_FIELD.
    * get reference of ALV component
      lr_salv_wd_table = wd_this->wd_cpifc_OVERVIEW_EARNED_ALV( ).
      wd_this->alv_config_table = lr_salv_wd_table->get_model( ).
    *  get function settings
      lr_function_settings ?= wd_this->alv_config_table.
    * display columns in correct order
      lr_column_settings ?= wd_this->alv_config_table.
      lt_column = lr_column_settings->get_columns( ).
      loop at lt_column into ls_column.
    CASE ls_column-id.
    when 'AMOUNT'
    * aggregate field
            CALL METHOD LR_FUNCTION_SETTINGS->IF_SALV_WD_FIELD_SETTINGS~GET_FIELD
              EXPORTING
                FIELDNAME = 'AMOUNT'
              RECEIVING
                VALUE     = lr_field_amnt.
    * create aggregate rule as total
            CALL METHOD LR_FIELD_AMNT->IF_SALV_WD_AGGR~CREATE_AGGR_RULE
              EXPORTING
                AGGREGATION_TYPE = IF_SALV_WD_C_AGGREGATION=>AGGRTYPE_TOTAL
              RECEIVING
                VALUE            = lv_aggr_rule.
    endcase.
    Regards
    Manas DUa

  • How can I display XSLT transformer errors on a web page ?

    Hi,
    I have some JSP pages that access DB, create an XML based on DB data and then transform it into HTML through an XSLT stylesheet. Developing the XSL code it's easy to make mistakes and generate errors on trasformation, but what I receive on the web page is only a "Could not compile stylesheet" TransformerConfigurationException, while the real cause of the error is displayed only on tomcat logs. This is the code for transformation:
    static public void applyXSLT(Document docXML, InputStream isXSL, PrintWriter pw) throws TransformerException, Exception {
            // instantiate the TransformerFactory.
            TransformerFactory tFactory = TransformerFactory.newInstance();
            // creates an error listener
            XslErrorListener xel = new XslErrorListener();
            // sets the error listener for the factory
            tFactory.setErrorListener(xel);
            // generate the transformer
            Transformer transformer = tFactory.newTransformer(new SAXSource(new InputSource(isXSL)));
            // transforms the XML Source and sends the output to the HTTP response
            transformer.transform(new DOMSource(docXML), new StreamResult(pw));
    }If an exception is thrown during the execution of this code, its error message is displayed on the web page.
    This is the listener class:
    public class XslErrorListener implements ErrorListener {
        public XslErrorListener() {
        public void warning(TransformerException ex) {
            // logs on error log
            System.err.println("\n\nWarning on XEL: " + ex.getMessage());
        public void error(TransformerException ex) throws TransformerException {
            // logs on error log
            System.err.println("\n\nError on XEL: " + ex.getMessage());
            // and throws it
            throw ex;
        public void fatalError(TransformerException ex) throws TransformerException {
            // logs on error log
            System.err.println("\n\nFatal Error on XEL: " + ex.getMessage());
            // and throws it
            throw ex;
    }When I have an error in the XSL stylesheet (for examples a missing closing tag), I can find on tomcat logs the real cause of the error:
    [Fatal Error] :59:10: The element type "table" must be terminated by the matching end-tag "</table>".
    Error on XEL: The element type "table" must be terminated by the matching end-tag "</table>".but on my web page is reported just the TransformerConfigurationException message that is:
    "Could not compile stylesheet".
    How can I display the real cause of the error directly on the web page?
    Thanks,
    Andrea

    This code is part of a bigger project that let developers edit XSL stylesheets through a file upload on the system and we can't impose the use of any tool for checking the xsl. So, I need to display the transformer error on the web page.I see. This code is part of an editorial/developmental tool for developers to create and edit XSL stylesheets.
    As part of the editorial process, XSL errors during editing can be considered a normal condition. In other words, it is normal to expect that the developers will generate XSL errors as they are developing stylesheets.
    In this light, handling the XSL transformation errors is a business requirement that you need to handle. Using the Java Exceptions mechanisms, e.g. try / catch are inappropriate to handle business requirements, in my opinion.
    I suggest that you look at how you handle the occurence of XSL errors differently than what you currently have. You need to:
    (1) capture the Transformation exception on the server;
    (2) extract the message from the exception and put it into a message that can be easily understood by the user;
    The current error message that you have going to the web browser is not useful.
    And you should not have the Transformation exception sent to the web browser either.
    What you are attempting to do with the exception is not appropriate.
    Handle the Transformation exception on the Business tier and use it to create a useful message that is then sent to the Presentation tier. In other words, do not send Java exceptions to web browser.
    />

  • How can I display True/False in my dropdownlist as "Yes" and "No"?

    Hi All,
    I want to bind a dropdownlist to a boolean value (so it's either true or false).  I'm particularly interested in using two-way binding to when the user changes from "yes" to "no" the boolean value automatically changes from "true" to "false."  But, I want the user to see "yes" and "no" as the options, rather than "true" and "false".
    How can I display "yes" and "no" and still take advantage of binding?  Or can I not use binding in this circumstance?
      -Josh

    Solution 1:
    In order to display Yes/No for True/False, you may specify labelFunction for the dropdownList.
    In MXML:
    <s:DropDownList labelFunction="myLabelFunction" />
    In actionscript:
    private var arr:ArrayCollection = new ArrayCollection(["true","false"]);
                private function mylabelFunction(item:Object):String
                    if(item.toString() == "true")
                        return "yes";
                    else return "No";
    OR
    Solution2:
    may be u can try making an array collection like
    private var arr:ArrayCollection = new ArrayCollection([{label:"yes",value:"true"},{label:"no",value:"false"}]);
    and specify labelField for the dropdownList like
    <s:DropDownList labelField="label" dataProvider="{arr}" />

  • How can I display  contacts in a relationship

    I have companies in my CRM. I have a customers/contacts in the CRM I have tied as a relationship with each companies. How can I display all the records/contacts associated with a company? I have a already created a secure zone, so the company user would have logged in. Is this possible? If not, any workaround?
    The only workaround I thought of is to use webapp to import the company data and create another web app containing the employees data. Then link both tables/webapp using datasource. But the way the client's data is structured could create a lot of problems going forward.
    Any suggestion, help will be appreciated

    The relationship feature and how companies work currently in BC is really limited. It is an association and not true relationships at the moment. You cant output a company and show all its relationships at the moment.

  • How can I display & split the audio & video from the same digitized clip?

    I digitized a scene into iMovie that I edited on a professional system which I don't have access to anymore. The whole scene is 1 clip. Now I see a few tweaks that I want to make, so I was hoping to do them in iMovie.
    I want to "pull up" the audio in one section - meaning I want to take cut about 20 frames of audio from the end of a shot, and then move all the other audio up to fill the hole. To compensate for the missing 20 frames, I'll cut video off the head of the next shot. Some call this prelapping. Some call it an L-cut. Some call it asymmetrical trimming. Either way, I can't figure out how to do it in iMovie.
    My clip appears in the timeline as one track - a single track that contains the video and 2 audio tracks. How can I display the audio that's tied to the video on its own track? Then I think I could split audio & video wherever I wanted and trim things up - but I can't figure out how to do it.
    Am I asking too much of this software?
    BTW, I never see the option to "Split audio clip at playhead". I'm not displaying clip volume or waveforms. Choosing to display waveforms doesn't show me anything. Maybe iMovie thinks I'd only want to see waveforms of audio that isn't tied to my video-and-audio clips?
    Thanks in advance for any help...

    Jordon,
    "Am I asking too much of this software?"
    No, you're not.
    You first want to select your clip(s) and choose Advanced>Extract Audio.
    This will copy the audio from the video clip and place it on one of the two separate audio tracks while lowering the audio level to zero in the original video track.
    You can now edit and move the audio independently of the video.
    With the audio clip selected, you'll find you now have access to Edit>Split Selected Audio Clip at Playhead.
    Matt

  • How can i display a list of all the names stored in the Mail app?

    When sending an email, the program shows a list of names according to the first and subsequent letters that I type into the To: field. There are times I cannot recall someone's email user name. How can I display a complete list of all the names Mail has stored? I know that I can go to the To: field then type in the letter A, then write down all listings under A, and then repeat for each letter of the alphabet, but there should be an easier method.
    I have perhaps dozens of names in Mail, but only five names in Address Book, so the latter does me no good.

    On the menubar, Mail > Window > Previous Recipients
    Regards,
    Captfred

Maybe you are looking for

  • Regarding Reading the file from Application Server

    Hi, I am trying to read data from Application Server but due to special characters it is getting dumped out. US24,Q,Acero (Carbon),AA,0010,0001,01,Ver Mir para dimension# US24,Q,Acero (Carbon),AA,0010,0002,01,Area rectificada sin da#os ra US24,Q,Acer

  • Cancel printing "Post.chge"

    Hi Friends, Through MIGO when I create a transfer order, it internally creating a spool request. In the header of the spool request it is printing "Post.chge". But I don't want that. How can I avoid this? Best Regards, Raghu

  • [SOLVED] X Server not accepting remote connections after update

    Hi everyone! After recent upgrade Xorg on my laptop not allows other machines to use him as a window server, just an example: on laptop: vitaly@trifon:~/VM$ ps aux | grep Xorg root       499  2.7  1.3 393628 105276 tty7    Ssl+ фев17 139:48 /usr/lib/

  • Catching Errors in Call Transaction

    Hi All, I have develop the BDC using call transaction for MM01 transaction but i need to catch the success messages as well as errors in a log file that i wanna download. below is the code for the same and is it mandatory to give the update mode.plea

  • Pdfs are suddenly damaged

    I manage several sites with iWeb. This past weekend I went into all and updated the copyright information in the footer of each page. Upon doing so, I am now realizing that even though I did not make other changes, many (not all) of the current pdfs