jtextfield

automatic font resize

微笑、不失礼 提交于 2019-12-13 21:51:57
问题 How can I find out, if a text in a JTextField is larger than visible area of these JTextField, so that I can change the font size? Thx for any help. Sincerely Christian 回答1: It is possible to compute the text width for a given font with the FontMetrics class and compare this length with the textfield width. JtextField field = new JTextField(); FontMetrics fm = field.getFontMetrics(field.getFont()); int textwidth = fm.stringWidth(field.getText()); 回答2: Instead, ask the JTextField how tall it

JTextField resizing upon minimize

天大地大妈咪最大 提交于 2019-12-13 15:11:53
问题 I have a JTextField as well as a JTextArea in a JFrame. When the application runs however, the JTextField gets resized if I minimize the window. It usually doubles or triples in height, but it's not consistent in how it resizes each time. I have no idea why this could be happening. I'm not really asking for a direct solution, just some possible things that could be causing the problem. If you could help me out here that'd be great. Thanks EDIT: here's the code I'm using to initialize it:

Why is iText's PdfWriter printing JTextFields black when exported as a runnable jar?

久未见 提交于 2019-12-13 12:37:21
问题 I hava got a strange conundrum. I am currently trying to make a Runnable Jar of an Eclipse project I'm working on that has a number of JTextField's and JFormattedTextField's all nicely arranged in JPanel's. I am then taking these JPanel's and printing them out use iText's nice PdfWriter. The issue is this: In Eclipse, this prints out just fine. When I export my project into a runnable jar, I get the following: All of those black rectangles are where my JTextField's and JFormattedTextField's

What does a JTextField look like in various LAF instances? [closed]

霸气de小男生 提交于 2019-12-13 11:19:52
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 10 months ago . What does a Swing text field look like when editable, not editable and disabled, across various Pluggable Look & Feel implementations? Below is an answer for PLAFs seen on Windows & Apple OS X. I'd also very much appreciate seeing the look on other PLAFs (e.g. GTK on *nix). 回答1:

Applet shows up blank, not initializing?

为君一笑 提交于 2019-12-13 09:36:46
问题 Hello everyone my name is Fyree! I have an assignment for an introductory Java course where I need to create a program that takes user input for the beginning values, and all five year values to make a line graph (but that is for another post), and also print the rate. Here is my problem, when I try to run this applet it opens (it compiles without error), but only shows up as a blank screen, and says applet not initialized at the bottom of the applet. I am not sure why this is (currently I am

Asking what is wrong with enterPressed method?

↘锁芯ラ 提交于 2019-12-13 08:37:34
问题 import javax.swing.*; import javax.swing.table.DefaultTableModel; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class GUI extends JFrame{ String [] col = {"Last Name", "First Name", "HKID", "Student ID", "Final Exam Score"}; String [][] data = new String [1][5]; public JFrame j; public JPanel p; public JLabel search; public JTextField s; public JButton enter; public JButton NEW; public JButton unedit; public JButton update; public JButton

Loading date into JTextField [closed]

前提是你 提交于 2019-12-13 08:14:11
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I had some problems loading a date into a JTextField . What mistakes did I make? public static void main(String args[]) { try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager

Parsing JTextfield String into Integer

ε祈祈猫儿з 提交于 2019-12-13 07:01:05
问题 So I have this to convert String from JTextField to int . It says Exception in thread "main" java.lang.NumberFormatException: For input string: "" . Please help. JTextField amountfld = new JTextField(15); gbc.gridx = 1; // Probably not affecting anything gbc.gridy = 3; // add(amountfld, gbc); String amountString = amountfld.getText(); int amount = Integer.parseInt(amountString); 回答1: From docs: Throws: NumberFormatException - if the string does not contain a parsable integer. The empty String

Make method that returns when JButton is pressed

一个人想着一个人 提交于 2019-12-13 06:31:44
问题 I need to make a method that returns only when a JButton is pressed. I have a custom JButton class public class MyButton extends JButton { public void waitForPress() { //returns only when user presses this button } } and I want to implement waitForPress . Basically, the method should only return when the user presses the button with their mouse. I have achieved similar behavior for JTextField (to return only when user presses Space ): public void waitForTriggerKey() { final CountDownLatch

Update JTextFields text every change of variable

帅比萌擦擦* 提交于 2019-12-13 05:24:45
问题 Hello I I´m a very newbie in Java and I´m trying to write a very simple excercise to practice, I created a Jclass to read the parameter from a DB and save it in a variable called "estado" and a JFrame to show the value of this variable who is changing randomly in DB. The program read a MySql DB and store the data needed in a Java variable like these class: package Paquete_domotica; import java.io.*; import java.sql.*; public class domotica { public static int estado; boolean loop = true;