Java: network settings window

I am looking for a way to program text fields with dots similar to one of the Windows Network Settings dialog:

see → http://i.stack.imgur.com/gayeY.jpg

Is there a ready-to-use example on the net? - Unfortunately, I did not find anything.

Many thanks for your help!

-patrick

+2
source share
2 answers

With a simple google search, I found a JFormattedTextField , here on how to use it.


Example IP Address:

public static void main(String args[]) throws ParseException { JFrame frame = new JFrame("Test"); JTextField f = new JFormattedTextField(new MaskFormatter("###.###.###.###")); f.setFont(new Font("Monospaced", Font.PLAIN, 10)); frame.add(f); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(100, 50); frame.setVisible(true); } 
+2
source

As discussed earlier in the Stack Overflow section (see How to set a JFormattedTextField with a placeholder? ), You cannot easily use JFormattedTextField to enter IP addresses. However, there is also a RegexFormatter from Sun (see http://java.sun.com/products/jfc/tsc/articles/reftf/ ; download the source code http://java.sun.com/products/jfc/ tsc / articles / reftf / RegexFormatter.java ), which you can use as follows:

  JFormattedTextField ipAddress; try{ RegexFormatter ipmask = new RegexFormatter("\\d{0,3}\\.\\d{0,3}\\.\\d{0,3}\\.\\d{0,3}"); ipmask.setOverwriteMode(false); ipAddress = new JFormattedTextField(ipmask); }catch(Exception e1){ } ipAddress.setValue("255.255.255.255"); 

This will allow you to enter / edit the value and save the points on the output.

+2
source

Source: https://habr.com/ru/post/1286022/


All Articles