0

Since it is an array it repeats till the end of the loop. But Room 1 should not be repeated . it should be place at the top

first[ind] = new JLabel("<html>"
                        + "<body>"
                        + "<div id=r12style=border: 3px solid orange; margin-bottom: 5px;>"
                        + " <h2>"
                        + "   Room 1"
                        + " </h2>"
                        + "<img src=" + icon + " width=\"95\" height=\"105\"></img>"
                        + "</div>"
                        + "</body>"
                        + "</html>");
Akarsha
  • 29
  • 2
  • 7
  • 1
    Remember, Java/Swing only has a limited support for CSS and supports only HTML 3.2 – MadProgrammer Feb 17 '15 at 06:03
  • can i able to get this.......

    Room 1

    – Akarsha Feb 17 '15 at 06:05
  • please try asking real questions, asking "can i able to get this " is so unclear we cannot help you – Peter Feb 17 '15 at 06:08
  • You can use an extra DIV in HTML for an HTML aware Swing component just as you might use it in HTML for a web page. Get it working (and validated) first as HTML 3.2, and it should be copy/paste/fine for Java. Also, please don't put code or HTML snippets in comments where it is unreadable, instead [edit the question](http://stackoverflow.com/posts/28555633/edit). – Andrew Thompson Feb 17 '15 at 06:10
  • Also remember, you'll need to supply the CSS for each `` block, Swing doesn't remember it across different instances – MadProgrammer Feb 17 '15 at 06:12
  • Why not you use JavaFX? it is an amazing framework you will love it :-) – Muhammad Feb 17 '15 at 06:13
  • In the included snippet of HTML (now edited into the question), I notice 3 ` – Andrew Thompson Feb 17 '15 at 06:15
  • Nice edit @Muhammad. :) I had not realized that the 'code snippets' ability could deal with HTML fragments. I hot-linked an image from [Example images for code and mark-up Q&As](http://stackoverflow.com/q/19209650/418556). – Andrew Thompson Feb 17 '15 at 07:09

1 Answers1

0

Try this (I haven't tested it):

IMM[ind] = new JLabel("<html><style >#aa {margin-left:25px;}</style>"
                + "<div id=\"aa\"></font><font color=\"rgb(0,0,0)\"size=\"5\">" 
                + bed_no + "<font color=\"rgb(255, 204, 204, 150)\"size=\"1\">.</div></font></html>"
                 , "<html><img src=" + icon + "></html>", JLabel.LEFT_ALIGNMENT);

If you want the text under the icon:

IMM[ind].setHorizontalTextPosition(JLabel.CENTER);
IMM[ind].setVerticalTextPosition(JLabel.BOTTOM);

Edit - It's probably a good idea to break up the JLabel text by using a String variable. Because it looks almost unreadable.

ARM
  • 11
  • 2
  • , "", JLabel.LEFT_ALIGNMENT); this part is not working – Akarsha Feb 17 '15 at 06:31
  • *"this part is not working"* What exactly do you mean by 'not working'? Is the image loaded? Note that is invalid HTML. The `img` element requires both `width` and `height` to be defined. – Andrew Thompson Feb 17 '15 at 06:37
  • (Again) **[edit the question](http://stackoverflow.com/review/suggested-edits/7069632)** with this new information.. But for better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete Verifiable Example) or [SSCCE](http://www.sscce.org/) (Short, Self Contained, Correct Example). ..I am hovering as to whether to supply the 5th and last 'close vote' to this question. Ignoring advice offered is making me think it should be closed.. – Andrew Thompson Feb 17 '15 at 06:41