下面列出了javax.swing.JScrollPane#setSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public SimpleInfoBox( final String title, final String text )
{
frame = new JFrame( title );
final JTextArea textarea = new JTextArea( text );
final JPanel panel = new JPanel();
panel.add( textarea, BorderLayout.CENTER );
final JScrollPane pane = new JScrollPane( panel );
frame.add( pane, BorderLayout.CENTER );
frame.pack();
final Dimension d = pane.getSize();
d.setSize( d.width + 20, d.height + 10 );
pane.setSize( d );
pane.setPreferredSize( d );
frame.setPreferredSize( d );
frame.pack();
frame.setVisible( true );
}
@Override
public void mouseDragged(MouseEvent e) {
Point p = e.getPoint();
if(mousePressedInTriangle) {
inTheTriangleZone = true;
int yDiff = (mousePressedPoint.y - p.y);
newSize = new Dimension(100, sizeAtPress.height - yDiff);
JScrollPane sp = getScrollPane();
if(scrollPane != null) {
sp.getViewport().setSize(newSize);
sp.getViewport().setPreferredSize(newSize);
sp.getViewport().setMinimumSize(newSize);
sp.setSize(newSize);
sp.setPreferredSize(newSize);
sp.setMinimumSize(newSize);
}
scriptQueryPanel.setSize(scriptQueryPanelWidth, scriptQueryPanelHeight - yDiff);
scriptQueryPanel.revalidate();
scriptQueryPanel.repaint();
}
}
@Override
public void mouseDragged(MouseEvent e) {
Point p = e.getPoint();
if(mousePressedInTriangle) {
inTheTriangleZone = true;
int yDiff = (mousePressedPoint.y - p.y);
newSize = new Dimension(100, sizeAtPress.height - yDiff);
JScrollPane sp = getScrollPane();
if(scrollPane != null) {
sp.getViewport().setSize(newSize);
sp.getViewport().setPreferredSize(newSize);
sp.getViewport().setMinimumSize(newSize);
sp.setSize(newSize);
sp.setPreferredSize(newSize);
sp.setMinimumSize(newSize);
}
tmqlPanel.setSize(tmqlPanelWidth, tmqlPanelHeight - yDiff);
tmqlPanel.revalidate();
tmqlPanel.repaint();
}
}
ResultStatisticTab(String planName, Map<String, List<TimeSeriesStatistics>>
timeseriesStatistics, TabCloseCallBack closeCallBack) {
super(planName, closeCallBack);
table = new JTable();
Box box = Box.createVerticalBox();
// the header and the data should be added separately
box.add(table.getTableHeader());
box.add(table);
// provides a scroll bar for many series
JScrollPane scrollPane = new JScrollPane(box);
scrollPane.setLocation(0, 100);
scrollPane.setSize(800, 600);
add(scrollPane);
Object[] header = TimeSeriesStatistics.HEADER;
List<TimeSeriesStatistics> allStatistics = new ArrayList<>();
for (List<TimeSeriesStatistics> seriesStatistics : timeseriesStatistics.values()) {
allStatistics.addAll(seriesStatistics);
}
allStatistics.sort(Comparator.comparing(TimeSeriesStatistics::getName));
Object[][] data = new Object[allStatistics.size()][];
for (int i = 0; i < allStatistics.size(); i++) {
data[i] = allStatistics.get(i).toArray();
}
tableModel = new DefaultTableModel(data, header);
table.setModel(tableModel);
// enable sort by column
table.setRowSorter(new TableRowSorter<>(tableModel));
}
private void initModels() {
setSize(375, openModels.size() * 265 + 50);
setTitle("Manage Plots Seawater/Open Sys Isochrons");
setAlwaysOnTop(true);
JPanel modelsPanel = new JPanel(null);
modelsPanel.setSize(300, openModels.size() * 250);
modelsPanel.setBackground(new Color(249, 237, 189));
modelsPanel.setPreferredSize(new Dimension(300, openModels.size() * 265 + 25));
int count = 0;
for (OpenSystemIsochronTableModel osm : openModels) {
JPanel openPanel = new OpenSystemModelDataView(osm);
openPanel.setBounds(10, count * 245 + 10, 300, 235);
modelsPanel.add(openPanel);
count++;
}
JButton okButton = new ET_JButton("OK");
okButton.setBounds(15, count * 245 + 10, 290, 25);
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
});
modelsPanel.add(okButton);
JScrollPane modelsScroll = new JScrollPane(modelsPanel);
modelsScroll.setSize(300, openModels.size() * 265);
setContentPane(modelsScroll);
}
/**
* Displays the dialog
*
* @return a String, containing the selected character OR null, if nothing was selected
*/
public String showModal() {
final JScrollPane listScrollPane = new JScrollPane(hexList);
listScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
listScrollPane.setSize(40,100);
final JPanel srp = new JPanel();
srp.setLayout(new BorderLayout());
srp.add(listScrollPane,BorderLayout.CENTER);
final String[] options = {LangTool.getString("hm.optInsert"), LangTool.getString("hm.optCancel")};
int result = JOptionPane.showOptionDialog(
parent, // the parent that the dialog blocks
new Object[] {srp}, // the dialog message array
LangTool.getString("hm.title"), // the title of the dialog window
JOptionPane.DEFAULT_OPTION, // option type
JOptionPane.INFORMATION_MESSAGE, // message type
null, // optional icon, use null to use the default icon
options, // options string array, will be made into buttons//
options[0] // option that should be made into a default button
);
if (result == 0) {
final String selval = (String) hexList.getSelectedValue();
return selval.substring(selval.length()-1);
}
return null;
}