-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scrolling panel with toolbar at top example. (#159)
- Loading branch information
1 parent
9b0a0d3
commit 881467b
Showing
2 changed files
with
48 additions
and
0 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
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,46 @@ | ||
package basic; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
|
||
public class ScrollingWithToolbarPanel extends BasePanel { | ||
public ScrollingWithToolbarPanel() { | ||
super("Scrolling With Toolbar", "scroll-with-toolbar"); | ||
|
||
setLayout(new GridBagLayout()); | ||
|
||
JToolBar toolBar = new JToolBar(); | ||
toolBar.add(new JButton("Add")); | ||
toolBar.add(new JButton("Remove")); | ||
|
||
JPanel panel = new JPanel(); | ||
panel.setLayout(new GridBagLayout()); | ||
|
||
GridBagConstraints gbc = new GridBagConstraints(); | ||
gbc.gridx = 0; | ||
gbc.gridy = 0; | ||
gbc.weightx = 1; | ||
gbc.weighty = 0; | ||
gbc.fill = GridBagConstraints.HORIZONTAL; | ||
|
||
for (int i = 0; i < 30; i++) { | ||
panel.add(new JLabel("label " + i), gbc); | ||
gbc.gridy++; | ||
} | ||
|
||
gbc.gridy = 0; | ||
add(toolBar, gbc); | ||
|
||
gbc.gridy++; | ||
gbc.weightx = 1; | ||
gbc.weighty = 1; | ||
gbc.fill = GridBagConstraints.BOTH; | ||
|
||
add(new JScrollPane(panel), gbc); | ||
} | ||
|
||
@Override | ||
public boolean isWrappableInScrollpane() { | ||
return false; | ||
} | ||
} |