How to read UTF8 encoded file using RandomAccessFile?

You can convert string, read by readLine to UTF8, using following code: public static void main(String[] args) throws IOException { RandomAccessFile raf = new RandomAccessFile(new File(“MyFile.txt”), “r”); String line = raf.readLine(); String utf8 = new String(line.getBytes(“ISO-8859-1”), “UTF-8”); System.out.println(“Line: ” + line); System.out.println(“UTF8: ” + utf8); } Content of MyFile.txt: (UTF-8 Encoding) Привет из Украины Console … Read more

JavaFX 2.2 TextField maxlength

This is a better way to do the job on a generic text field: public static void addTextLimiter(final TextField tf, final int maxLength) { tf.textProperty().addListener(new ChangeListener<String>() { @Override public void changed(final ObservableValue<? extends String> ov, final String oldValue, final String newValue) { if (tf.getText().length() > maxLength) { String s = tf.getText().substring(0, maxLength); tf.setText(s); } } … Read more

How to create number input field in Flutter?

You can specify the number as keyboardType for the TextField using: keyboardType: TextInputType.number Check my main.dart file import ‘package:flutter/material.dart’; import ‘package:flutter/services.dart’; void main() => runApp(new MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { // TODO: implement build return new MaterialApp( home: new HomePage(), theme: new ThemeData(primarySwatch: Colors.blue), ); } } class HomePage … Read more

Only allow certain characters to be entered in html textinput

You can change your input text as below: <input type=”text” pattern=”[a-zA-Z0-9!@#$%^*_|]{6,25}” /> So the code changes look like below: <form action=”#” method=”get”> User Name:<br /> <input type=”text” pattern=”[a-zA-Z0-9!@#$%^*_|]{6,25}” /><br /> Password:<br /> <input type=”password” /><br /> <input type=”submit” value=”Log In” /> </form> This will work without using JavaScript. pattern can be used instead. It is … Read more

How to shift focus to the next TextField in Flutter?

Screenshot: Just use: textInputAction: TextInputAction.next: To move the cursor to the next field. textInputAction: TextInputAction.done: To close the keyboard. @override Widget build(BuildContext context) { return Scaffold( body: Column( children: <Widget>[ TextField( decoration: InputDecoration(hintText: ‘TextField A’), textInputAction: TextInputAction.next, // Moves focus to next. ), TextField( decoration: InputDecoration(hintText: ‘TextField B’), textInputAction: TextInputAction.next, // Moves focus to next. … Read more

Java – placeholder on textfield

I found this on the oracle forums. public class TextFieldWithPrompt extends JTextField{ @Override protected void paintComponent(java.awt.Graphics g) { super.paintComponent(g); if(getText().isEmpty() && ! (FocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == this)){ Graphics2D g2 = (Graphics2D)g.create(); g2.setBackground(Color.gray); g2.setFont(getFont().deriveFont(Font.ITALIC)); g2.drawString(“zip”, 5, 10); //figure out x, y from font’s FontMetrics and size of component. g2.dispose(); } } https://forums.oracle.com/forums/thread.jspa?threadID=1349874

Resize textField Based On Content

You have to use an UITextView instead of an UITextField. Then, you can use the sizeThatFits method. But first you have to know how high one line will be. You can get that information by using lineHeight: var amountOfLinesToBeShown: CGFloat = 6 var maxHeight: CGFloat = yourTextview.font.lineHeight * amountOfLinesToBeShown After that, just call the sizeThatFits … Read more