Do you really want the scrollbars all of the time? The drag-and-drop didn't seem to do anything.
Swing is great and I like the layout managers, etc. There is a deficiency in being able to have a child component negotiate horiz and vert sizing preferences at the same time. I'm not sure, but it might be a little cleaner to write your own layout manager (possibly used with a custom component) to do this. This at least separates some of the layout vs other stuff. Also, not sure if it helps or not, but with Java 1.4 or so, Jlist gained the ability to do multi-column lists. I haven't used it, though. The javadoc looks like you can select which way the columns flow. You'd probably need a custom renderer, etc., maybe fiddle with prototypical cells, etc. to do stuff, but Jlist might be able to do a lot of the layout work for you. Will all displayed items be fixed size? Or at least fixed in one dimension? Good luck, Joel > -----Original Message----- > From: steven alyari [mailto:[EMAIL PROTECTED] > Sent: Saturday, December 20, 2003 3:28 AM > To: steven alyari > Cc: [EMAIL PROTECTED] > Subject: Re: JPanel question > > > cool, > > it appears i have completely answered my initial question; it appears > that my JPanel behaves exactly how I want. The credit to > this goes to > this mailing list and the mailing list on sun's java site and the sun > java site. Anyway, my question is, what do you think of the solution? > > MyTest3.java: > > import javax.swing.*; > import javax.swing.border.*; > import java.awt.*; > import java.awt.dnd.*; > import java.awt.datatransfer.*; > import java.awt.event.*; > import java.io.*; > import java.util.*; > import java.lang.*; > > public class MyTest3 { > static OPanel p = new OPanel( ); > public static void main(String[] args) { > JFrame f = new JFrame("Moo"); > p.setPreferredSize(new Dimension(300,300)); > JScrollPane sp = new JScrollPane(p, > JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, > JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); > p.setScrollPane(sp); > for( int i=0; i<20; i++ ) > p.add( new JButton(""+i) ); > p.setAutoscrolls(true); > MouseMotionListener doScrollRectToVisible = new > MouseMotionAdapter() { > public void mouseDragged(MouseEvent e) { > Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1); > ((JPanel)e.getSource()).scrollRectToVisible(r); > } > }; > p.addMouseMotionListener(doScrollRectToVisible); > sp.addComponentListener( > new ComponentAdapter() { > public void componentResized( ComponentEvent ev ) { > JComponent c = (JComponent)ev.getSource(); > Insets i = c.getInsets(); > p.setPreferredSize( > new Dimension( > c.getWidth()-i.left-i.right, > c.getHeight()) > ); > p.revalidate(); > } > } > ); > p.addComponentListener( > new ComponentAdapter() { > public void componentResized( ComponentEvent ev ) { > JComponent c = (JComponent)ev.getSource(); > Dimension currentPrefSize = c.getPreferredSize(); > Component lastComp = c.getComponent( > c.getComponentCount()-1 ); > int newHeight = lastComp.getLocation().y + > lastComp.getHeight() + c.getInsets().bottom; > currentPrefSize.height = newHeight; > c.setPreferredSize( currentPrefSize ); > c.revalidate(); > } > } > ); > > f.setContentPane(sp); > f.setSize(300,300); > f.setVisible(true); > } > } > > class OPanel extends JPanel implements Scrollable { > private JScrollPane sp; > public OPanel( ) { } > public void setScrollPane(JScrollPane sp) { this.sp = sp; } > public Dimension getPreferredScrollableViewportSize( ) { return > getPreferredSize( ); } > public int getScrollableBlockIncrement(Rectangle visibleRect, int > orientation, int direction) { return 10; } > public boolean getScrollableTracksViewportHeight( ) { > if (this.getHeight( ) > sp.getViewport( ).getHeight( )) > return false; > else > return true; > } > public boolean getScrollableTracksViewportWidth( ) { > return true; } > public int getScrollableUnitIncrement(Rectangle visibleRect, int > orientation, int direction) { return 10; } > } > > _______________________________________________ > Advanced-swing mailing list > [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing > _______________________________________________ Advanced-swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing
