-1
私はいつもフォーカスされたJPanelを中心にしたいプロジェクトがあります。だから私はちょうどビューポートの位置を変更することができると思った。しかし、私はビューポートを使用することはできません。ビューポートの使い方を示すサンプルプロジェクトを作成しました。私はちょうどオレンジ色のボックスの1つを見ることをユーザーに望みます。しかし、すべてのボックスを一度に見ることも可能でなければなりません。したがって、ビューはズームインするか、このようなものが必要です。この問題を解決するにはどうすればよいですか? 私の例:フォーカスされたJPanelの中心を常に設定します
import javax.swing.*;
import java.awt.*;
public class main {
public static void main(String [] args){
//create JFrame
JFrame _frame = new JFrame();
//create Viewport
JViewport _view = new JViewport();
//create Mainpanel
JPanel _mainPanel = new JPanel();
//tell the view to handle mainpanel
_view.setView(_mainPanel);
//create Layout
GridLayout _layout = new GridLayout(3,3,3,3);
//set gridlayout to mainpanel
_mainPanel.setLayout(_layout);
for(int i = 0;i<12;i++){
JPanel _tempPanel = new JPanel();
_tempPanel.setBackground(Color.ORANGE);
_tempPanel.setBorder(BorderFactory.createLineBorder(Color.black));
_mainPanel.add(_tempPanel);
}
_view.setExtentSize(new Dimension(300,300));
//add mainpanel to frame
_frame.add(_mainPanel);
_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
_frame.pack();
//set size of Jframe
_frame.setSize(1000,1000);
_frame.setVisible(true);
}
}
なぜ[cardlayout](https://docs.oracle.com/javase/tutorial/uiswing/layout/card.html)を使用していない – guleryuz
@guleryuzねえ、私はすべてのJPanelを表示することが可能にしたいので、一度 – ReasyEasyPeasy
"私はちょうどあなたがあなたの質問で言うオレンジ色のボックスの1つを参照してほしい" – guleryuz