changeset 3:6e29262ee18c

Added card widget
author Fox
date Fri, 01 Apr 2022 03:03:43 +0200
parents 19b163992f3b
children 1b754922d6af
files src/junotu/CardWidget.java src/junotu/TabSimpleSearch.java
diffstat 2 files changed, 67 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/junotu/CardWidget.java	Fri Apr 01 03:03:43 2022 +0200
@@ -0,0 +1,62 @@
+package junotu;
+
+import java.awt.Font;
+import java.awt.Dimension;
+import java.awt.GridBagConstraints;
+import javax.swing.BorderFactory;
+
+import javax.swing.JPanel;
+
+import java.awt.GridBagLayout;
+
+import javax.swing.JLabel;
+import javax.swing.JTextArea;
+
+public class CardWidget extends JPanel {
+
+    public CardWidget()
+    {
+	this( "Title" );
+    }
+    
+    public CardWidget( String titleStr )
+    {
+	this( titleStr, "Content" );
+    }
+    
+    public CardWidget( String titleStr, String contentStr )
+    {
+	this.setLayout( new GridBagLayout() );
+
+	JLabel title = new JLabel( titleStr, JLabel.LEFT );
+	JTextArea content = new JTextArea( contentStr );
+
+	title.setFont( new Font( "Monospaced", Font.BOLD, 16 ) );
+	content.setFont( new Font( "Monospaced", Font.PLAIN, 12 ) );
+	
+	this.setMinimumSize( new Dimension( 96, 32 ) );
+	this.setPreferredSize( new Dimension( 128, 128 ) );
+	this.setMaximumSize( new Dimension( 1000000000, 128 ) );
+
+	title.setMinimumSize( new Dimension( 32, 32 ) );
+
+	this.setBorder( BorderFactory.createRaisedBevelBorder() );
+	content.setEditable( false );
+	content.setLineWrap( true );
+	content.setWrapStyleWord( true );
+	content.setOpaque( false );
+	
+	GridBagConstraints constraints = new GridBagConstraints();
+	constraints.anchor = GridBagConstraints.WEST;
+	constraints.fill = GridBagConstraints.HORIZONTAL;
+	constraints.weightx = 1.0;
+	
+	this.add( title, constraints );
+	constraints.anchor = GridBagConstraints.NORTHWEST;
+	constraints.gridx++;
+	constraints.fill = GridBagConstraints.BOTH;
+	constraints.weighty = 0.5;
+	this.add( content, constraints );
+	
+    }
+}
--- a/src/junotu/TabSimpleSearch.java	Fri Apr 01 01:32:38 2022 +0200
+++ b/src/junotu/TabSimpleSearch.java	Fri Apr 01 03:03:43 2022 +0200
@@ -4,14 +4,16 @@
 import java.awt.Font;
 
 import javax.swing.JPanel;
+import javax.swing.Box;
 
 import java.awt.BorderLayout;
 
-import javax.swing.Box;
 import javax.swing.JButton;
 import javax.swing.JTextField;
 import javax.swing.JScrollPane;
 
+import junotu.CardWidget;
+
 public class TabSimpleSearch extends JPanel {
     public TabSimpleSearch()
     {
@@ -36,10 +38,8 @@
 
 	this.add( scroll, BorderLayout.CENTER );
 	for( int i = 0; i < 100; i++ ) {
-	    JButton button = new JButton( "Placeholder #"+Integer.toString(i+1) );
-	    button.setPreferredSize( new Dimension( 128, 128 ) );
-	    button.setMaximumSize( new Dimension( 1000000, 128 ) );
-	    results.add( button );
+	    CardWidget card = new CardWidget( "Placeholder #"+Integer.toString(i+1) );
+	    results.add( card );
 	}
 
 	scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);