Re: Replacing the JList as the JComboBox popup
Farwell, Paul [EMAIL PROTECTED] asked: We have a calendar component that we want displayed when the user clicks the JComboBox arrow. Does anyone know a relatively painless way to set a component -- other than the default JList -- as the popup item in a JComboBox? In looking at the JComboBox source and its delegates (e.g. BasicComboBoxUI, BasicComboPopup) it looks as if JList is pretty tightly coupled as the JComboBox's popup component. Yes, I couldnt find a way to replace JList. I ended up building my own, wasnt as hard as subclassing JComboBox. If you want to look at what i did, you can get our (LGPL) source snapshot at ftp://ftp.unidata.ucar.edu/pub/metapps/metapps_src.jar and look at ucar.unidata.ui.SuperComboBox. Regards, John ___ Advanced-swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing
JTable tooltip placement
This is a continuation of the JTable and ToolTips per Cell thread from January 4, 2001. To summarize, to add tooltips to a JTable, extend the CellRenderer, eg: jtable = new JTable(); jtable.setDefaultRenderer(Object.class, new MyTableCellRenderer() ); ToolTipManager.sharedInstance().registerComponent(jtable); private class MyTableCellRenderer extends javax.swing.table.DefaultTableCellRenderer { public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component c = super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column); if (value instanceof NamedObject) { ((JComponent)c).setToolTipText(((NamedObject)value).getDescription()); } // LOOK!! should turn tip off if there is none !! return c; } } So this works fine except that the placement of the tooltip is wrong when the JTable is on the left edge of the screen, in which case long tooltips get their left part chopped off. For some reason the ToolTipManager doesnt do its normal job of placing tooltips correctly near the window edge. Now if I add a getToolTipLocation() method to MyTableCellRenderer, it never gets called. When I add getToolTipLocation() method to the JTree, the tooltip blinks like crazy like its in some loop, then sometimes finally displays the tooltip, but in the same location as before. // add tooltips private class MyJTable extends javax.swing.JTable { public Point getToolTipLocation(MouseEvent e) { return e.getPoint(); } } If getToolTipLocation() returns null, then I get the previous behavior of chopping off the edge of the screen. This is all in JDK 1.3. Anyone have any ideas on why the tooltip location is unusual? thanks, John Caron ___ Advanced-swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing
Re: ChangedCharSetException from HTMLEditorKit.Parser
I am trying to use the javax.swing.text.html.HTMLEditorKit.Parser to parse some web pages (using code from Elliotte Harold's "Java Network Programming" 2nd ed (oreilly). I gets javax.swing.text.ChangedCharSetException on most pages because (it seems) Netscape Composer embeds this in each page: head meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" meta name="GENERATOR" content="Mozilla/4.76 [en] (Windows NT 5.0; U) [Netscape]" meta name="Author" content="John Caron" titleGDV WebStart/title /head and it seems that "text/html; charset=iso-8859-1" always causes an Exception. Here's a brute-force workaround for this kind of problem, i just remove the offending lines before parsing the HTML. If anyone has more info on what HTMLEditorKit.ParserCallback can and cant do, or better ways to parse HTML, please post. ... baseURL = new URL(urlName); InputStream in = baseURL.openStream(); InputStreamReader r = new InputStreamReader(filterTag(in)); HTMLEditorKit.ParserCallback callback = new MyCallerBacker(); parser.parse(r, callback, false); ... // workaround for HTMLEditorKit.Parser, cant deal with "content-encoding" private InputStream filterTag(InputStream in) throws IOException { DataInputStream dins = new DataInputStream( in); ByteArrayOutputStream bos = new ByteArrayOutputStream(1); DataInputStream din = new DataInputStream(new BufferedInputStream(in)); while (din.available() 0) { String line = din.readLine(); String lline = line.toLowerCase(); if (0 = lline.indexOf("meta ")) // skip meta tags continue; //System.out.println("--"+line); bos.write( line.getBytes()); } din.close(); return new ByteArrayInputStream( bos.toByteArray()); } ___ Advanced-swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing