简体   繁体   English

Java中的jTextfield显示问题

[英]jTextfield display problem in java

I have made a frame in which i have put two jTextfield boxes where the user can see the path of the loaded file. 我做了一个框架,在其中放置了两个jTextfield框,用户可以在其中查看已加载文件的路径。 Problem is that if the path is too long , the textfield expands to accomodate the full path which again leads to display problems. 问题是,如果路径太长,则文本字段会扩展以适应完整路径,这又会导致显示问题。 I would like to keep the textfield's length constant and instead , display the full path of file as a tooltip instead. 我想保持文本字段的长度不变,而是将文件的完整路径显示为工具提示。

How can this be done? 如何才能做到这一点?

Code for layout manager of jinternal Frame: jinternal Frame布局管理器的代码:

   javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
    jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);

I never use an IDE so I don't know how the GroupLayout works. 我从不使用IDE,所以我不知道GroupLayout的工作方式。

But when using the other layout managers I always use: 但是当使用其他布局管理器时,我总是使用:

JTextField textField = new JTextField(10); // or whatever size your want

This will give the text field a preferred size and the layout manager can use that information when laying out the component. 这将为文本字段提供一个首选大小,并且布局管理器在布局组件时可以使用该信息。

Code the GUI by hand instead. 而是手动编写GUI。 You will avoid problems like this and it will be much easier to make changes to your code. 您将避免此类问题,并且对代码进行更改将更加容易。

you need to choose a layout manager to manage the proportions of your JComponents. 您需要选择一个布局管理器来管理JComponents的比例。 Try to put your textfiels on a JPanel so you can select a layout useful for you 尝试将文本文件放在JPanel上,以便选择对您有用的布局

Later you can use JTextField. 以后您可以使用JTextField。 setToolTip("full path") to set a tool tip setToolTip(“ full path”)设置工具提示

I solved my problem: Anybody having the same problem can set the Property Columns using Netbeans. 我解决了我的问题:任何有相同问题的人都可以使用Netbeans来设置属性列。 The default is 0, so the textfield cannot accomodate the full text. 默认值为0,因此文本字段无法容纳全文。 Use some value like 3 to achieve it. 使用一些像3这样的值来实现它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM