Note that there are some explanatory texts on larger screens.

plurals
  1. POMake HTML table inside JList cell as wide as the cell
    primarykey
    data
    text
    <p>I'm using HTML to style a cell inside JList -- it's a simple two-row table, where the second row has a non-default background. I want that row to span the whole width of the cell, instead of having it only as wide as the text inside it is.</p> <p>Here's an example:</p> <pre><code>import java.util.ArrayList; import javax.swing.JFrame; import javax.swing.JList; public class Example { public static void main(String[] args) { JFrame frame = new JFrame(); String html = "&lt;html&gt;"; html += "&lt;style type=\"text/css\"&gt;" + "body { margin: 0px auto; }\n" + "td { padding: 0px; margin: 0px; }\n" + "&lt;/style&gt;"; html += "&lt;body&gt;&lt;table&gt;"; html += "&lt;tr&gt;&lt;td&gt;line1&lt;/td&gt;&lt;/tr&gt;"; html += "&lt;tr&gt;&lt;td bgcolor=blue color=white&gt;line2&lt;/td&gt;&lt;/tr&gt;"; html += "&lt;body&gt;&lt;/table&gt;&lt;/html&gt;"; ArrayList&lt;String&gt; dataList = new ArrayList(); dataList.add(html); JList list = new JList(dataList.toArray()); frame.getContentPane().add(list); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } } </code></pre> <p>"line2" has blue background, but only under the text. I want it to go all the way to the end of the window, essentially making the table (or row) width 100% of the cell width.</p> <p>I tried placing "width:100%" in various places, with no effect. The only thing that worked was setting the td {width...} to a specific pixel width, but then I'll need a custom cell renderer to change that width every time the window/component is resized... and it seems like there must be a simple html/css-only solution to this problem.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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