Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a way to minimize the lines for this

Tags:

java

Is there anyway to minimize the number of lines of code to achieve the same thing

    L1.setFont(new Font("Serief", Font.BOLD, 24));
    L2.setFont(new Font("Serief", Font.BOLD, 24));
    L3.setFont(new Font("Serief", Font.BOLD, 24));
    L4.setFont(new Font("Serief", Font.BOLD, 24));
    L5.setFont(new Font("Serief", Font.BOLD, 24));
    L6.setFont(new Font("Serief", Font.BOLD, 24));
    L7.setFont(new Font("Serief", Font.BOLD, 24));
    L8.setFont(new Font("Serief", Font.BOLD, 24));
like image 739
Nestlewater Avatar asked Nov 15 '16 09:11

Nestlewater


People also ask

How to reduce line spacing in word?

How to Reduce Line Spacing in Word 1 Open File and Select Text As you launch Word, you need to open the respective file that you wish to format. ... 2 Select Text and Approach Scale From the “Home” tab, you need to navigate to the “Paragraph” section and select the option of “Line and Paragraph Spacing” to open ... 3 Set Line Spacing

How do I get to the end of a line?

Although, a faster way to get to the end of line is probably <Esc>A. So, to sum up, the above can be produced by typing System.out.println (foo ("<Esc>A;. For editing paired characters, as opposed to inserting them, see surround.vim. Show activity on this post.

What is the smallest value for line spacing that is available?

The smallest value for line spacing that is available is 1.0 in the options. You can access the “Line Spacing Options…” present in the list to set a value of your own.

What is the best way to close brackets?

A good IDE (galileo is almost here) will auto close brackets, parentheses, etc, and will intelligently insert a semicolon at the end of the statement too. No need to use arrows at all!


1 Answers

You could do

Font serif = new Font("Serif ", Font.BOLD, 24);
for (JLabel l : new JLabel[] { L1, L2, L3, L4, L5, L6, L7, L8 })
    l.setFont(serif);

In Java 8 you could write

Stream.of(L1, L2, L3, L4, L5, L6, L7, L8).forEach(l -> l.setFont(serif));
like image 184
Peter Lawrey Avatar answered Oct 04 '22 05:10

Peter Lawrey