Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible - border layout location from values form array?
    primarykey
    data
    text
    <p>I have 5 labels in grid layout frame. I would like to change gridlayout to border layout with using names of location from an array (e.g. String gborders[] = { "North", "Center", "South", "East", "West" }; ) and enumerate label location. Is it possible?</p> <p>That is what I have:</p> <pre><code>package w1; import java.awt.*; import javax.swing.border.*; import javax.swing.*; public class LayShow { private static JLabel lLabel; public static void main(String[] args) { int t = 15; String lmNames[] = {"Label 1", "Label 2", "Label 3", "Label 4", "Label 5"}; String gborders[] = { "North", "Center", "South", "East", "West" }; Color colors[] = { new Color(11, 125, 155), new Color(155, 55, 200), new Color(201, 245, 145), new Color(255, 255, 140), new Color(161, 224, 224), new Color(11, 125, 155) }; Font fonts[] = {new Font("SansSerif", Font.BOLD, t), new Font("Arial", Font.BOLD, t+1), new Font("SansSerif", Font.PLAIN, t+2), new Font("SansSerif", Font.ITALIC, t+3), new Font("SansSerif", Font.ITALIC, t+4)}; JFrame frame = new JFrame("Frame"); frame.setLayout(new GridLayout(0, 2)); for (int i = 0; i &lt; lmNames.length; i++) { final Border borderColor = BorderFactory.createLineBorder(colors[i+1]); JPanel p = new JPanel(); p.setBackground(colors[i]); p.setBorder(BorderFactory.createTitledBorder(borderColor , lmNames[i])); lLabel = new JLabel("label number: " + (i+1)); p.add(lLabel); lLabel.setFont(fonts[i]); lLabel.setForeground(colors[i+1]); lLabel.setToolTipText("ToolTip for label number: " + (i+1)); frame.add(p); } frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload