Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created small demo application using javax.swing.GroupLayout
- Loading branch information
1 parent
c91f937
commit 9d733bb
Showing
2 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package forms; | ||
|
||
import com.bulenkov.darcula.DarculaLaf; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
|
||
/** | ||
* Combo box demo. Created by sasha on 12/02/16. | ||
*/ | ||
public class ComboDemo { | ||
public static void main(String[] args) throws UnsupportedLookAndFeelException { | ||
UIManager.setLookAndFeel(new DarculaLaf()); | ||
JFrame f = new JFrame("Combo boxes"); | ||
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); | ||
Container contentPane = f.getContentPane(); | ||
|
||
JLabel label = new JLabel(); | ||
JComboBox comboBox = new JComboBox(); | ||
JTextField textField = new JTextField(); | ||
JComboBox comboBox2 = new JComboBox(); | ||
JButton button = new JButton(); | ||
JComboBox comboBox3 = new JComboBox(); | ||
JTextArea textArea = new JTextArea(); | ||
JComboBox comboBox4 = new JComboBox(); | ||
|
||
label.setText("label"); | ||
comboBox.setModel(new DefaultComboBoxModel(new String[]{"Item 1", "Item 2", "Item 3", "Item 4"})); | ||
textField.setText("textfield"); | ||
comboBox2.setModel(new DefaultComboBoxModel(new String[]{"Item 1", "Item 2", "Item 3", "Item 4"})); | ||
button.setText("button"); | ||
comboBox3.setModel(new DefaultComboBoxModel(new String[]{"Item 1", "Item 2", "Item 3", "Item 4"})); | ||
textArea.setRows(5); | ||
textArea.setColumns(10); | ||
textArea.setText("textArea\nother text\nanother text"); | ||
comboBox4.setModel(new DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); | ||
GroupLayout layout = new GroupLayout(contentPane); | ||
contentPane.setLayout(layout); | ||
layout.setHorizontalGroup( | ||
layout.createParallelGroup(GroupLayout.Alignment.LEADING) | ||
.addGroup(layout.createSequentialGroup() | ||
.addContainerGap() | ||
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) | ||
.addGroup(layout.createSequentialGroup() | ||
.addComponent(label) | ||
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) | ||
.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) | ||
.addGroup(layout.createSequentialGroup() | ||
.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) | ||
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) | ||
.addComponent(comboBox2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) | ||
.addGroup(layout.createSequentialGroup() | ||
.addComponent(button) | ||
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) | ||
.addComponent(comboBox3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) | ||
.addGroup(layout.createSequentialGroup() | ||
.addComponent(textArea, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) | ||
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) | ||
.addComponent(comboBox4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))) | ||
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) | ||
); | ||
layout.setVerticalGroup( | ||
layout.createParallelGroup(GroupLayout.Alignment.LEADING) | ||
.addGroup(layout.createSequentialGroup() | ||
.addContainerGap() | ||
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) | ||
.addComponent(label) | ||
.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) | ||
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) | ||
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) | ||
.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) | ||
.addComponent(comboBox2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) | ||
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) | ||
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) | ||
.addComponent(button) | ||
.addComponent(comboBox3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) | ||
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) | ||
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) | ||
.addComponent(textArea, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) | ||
.addComponent(comboBox4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) | ||
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) | ||
); | ||
f.pack(); | ||
f.setVisible(true); | ||
System.out.printf("comboBox baseline %d%n",comboBox.getBaseline(comboBox.getWidth(), comboBox3.getHeight())); | ||
System.out.printf("comboBox baseline resize behaviour %s%n", comboBox.getBaselineResizeBehavior()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters