本文整理汇总了Python中javax.swing.JFrame.setPreferredSize方法的典型用法代码示例。如果您正苦于以下问题:Python JFrame.setPreferredSize方法的具体用法?Python JFrame.setPreferredSize怎么用?Python JFrame.setPreferredSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFrame
的用法示例。
在下文中一共展示了JFrame.setPreferredSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import setPreferredSize [as 别名]
def __init__(self, imgData):
n = imgData.size()
win = JFrame("Point Marker Panel")
win.setPreferredSize(Dimension(350, 590))
win.setSize(win.getPreferredSize())
pan = JPanel()
pan.setLayout(BoxLayout(pan, BoxLayout.Y_AXIS))
win.getContentPane().add(pan)
progressPanel = JPanel()
progressPanel.setLayout(BoxLayout(progressPanel, BoxLayout.Y_AXIS))
positionBar = JProgressBar()
positionBar.setMinimum(0)
positionBar.setMaximum(n)
positionBar.setStringPainted(True)
progressPanel.add(Box.createGlue())
progressPanel.add(positionBar)
progressBar = JProgressBar()
progressBar.setMinimum(0)
progressBar.setMaximum(n)
progressBar.setStringPainted(True)
progressPanel.add(progressBar)
progressPanel.setBorder(BorderFactory.createEmptyBorder(0,10,0,10))
pan.add(progressPanel)
pan.add(Box.createRigidArea(Dimension(5,5)))
savePanel = JPanel()
savePanel.setLayout(BoxLayout(savePanel, BoxLayout.Y_AXIS))
saveMessageLabel = JLabel("<html><u>Save Often</u></html>")
savePanel.add(saveMessageLabel)
savePanel.setAlignmentX(Component.CENTER_ALIGNMENT)
savePanel.setBorder(BorderFactory.createEmptyBorder(0,10,0,10))
pan.add(savePanel)
# pan.add(saveMessageLabel)
pan.add(Box.createRigidArea(Dimension(5,5)))
calPanel = JPanel()
calPanel.setLayout(BoxLayout(calPanel, BoxLayout.Y_AXIS))
calPanelIn = JPanel()
calPanelIn.setLayout(BoxLayout(calPanelIn, BoxLayout.X_AXIS))
pixelSizeText = JTextField(12)
pixelSizeText.setHorizontalAlignment(JTextField.RIGHT)
# pixelSizeText.setMaximumSize(pixelSizeText.getPreferredSize())
unitText = JTextField(10)
# unitText.setMaximumSize(unitText.getPreferredSize())
pixelSizeText.setText("Enter Pixel Size Here")
calPanelIn.add(pixelSizeText)
unitText.setText("Unit")
calPanelIn.add(unitText)
calPanelIn.setAlignmentX(Component.CENTER_ALIGNMENT)
calPanelIn.setBorder(BorderFactory.createTitledBorder("Custom Calibration"))
calPanel.add(calPanelIn)
calPanelIn.setAlignmentX(Component.CENTER_ALIGNMENT)
calPanel.setBorder(BorderFactory.createEmptyBorder(0,10,0,10))
pan.add(calPanel)
pan.add(Box.createRigidArea(Dimension(5,5)))
helpPanel = JPanel()
helpPanel.setLayout(BoxLayout(helpPanel, BoxLayout.Y_AXIS))
helpLable = JLabel("<html><ul>\
<li>Focus on Image Window</li>\
<li>Select multi-point Tool</li>\
<li>Click to Draw Points</li>\
<li>Drag to Move Points</li>\
<li>\"Alt\" + Click to Erase Points</li>\
<li>Optional: Customize Calibration Above\
and Refresh Images\
(won't be written to files)</li>\
</html>")
helpLable.setBorder(BorderFactory.createTitledBorder("Usage"))
keyTagOpen = "<span style=\"background-color: #FFFFFF\"><b><kbd>"
keyTagClose = "</kbd></b></span>"
keyLable = JLabel("<html><ul>\
<li>Next Image --- " + keyTagOpen + "<" + \
keyTagClose + "</li>\
<li>Previous Image --- " + keyTagOpen + ">" + \
keyTagClose + "</li>\
<li>Save --- " + keyTagOpen + "`" + keyTagClose + \
" (upper-left to TAB key)</li>\
<li>Next Unmarked Image --- " + keyTagOpen + \
"TAB" + keyTagClose + "</li></ul>\
</html>")
keyLable.setBorder(BorderFactory.createTitledBorder("Keyboard Shortcuts"))
helpPanel.add(helpLable)
helpPanel.add(keyLable)
helpPanel.setAlignmentX(Component.CENTER_ALIGNMENT)
helpPanel.setBorder(BorderFactory.createEmptyBorder(0,10,0,10))
pan.add(helpPanel)
# pan.add(Box.createRigidArea(Dimension(0, 10)))
infoPanel = JPanel()
infoPanel.setLayout(BoxLayout(infoPanel, BoxLayout.Y_AXIS))
infoLabel = JLabel()
infoLabel.setBorder(BorderFactory.createTitledBorder("Project Info"))
infoPanel.add(infoLabel)
infoPanel.setAlignmentX(Component.CENTER_ALIGNMENT)
infoPanel.setBorder(BorderFactory.createEmptyBorder(0,10,0,10))
pan.add(infoPanel)
#.........这里部分代码省略.........
示例2: Gui
# 需要导入模块: from javax.swing import JFrame [as 别名]
# 或者: from javax.swing.JFrame import setPreferredSize [as 别名]
class Gui(MouseAdapter):
IMG_MIN_SIZE = 200
IMG_MAX_SIZE = 500
def __init__(self):
self.pos1 = None
self.puzzle = None
def mouseEntered(self, event):
self.in_canvas = True
def mouseExited(self, event):
self.in_canvas = False
def mouseReleased(self, event):
if not self.in_canvas or self.puzzle == None:
return
width = self.images_dict[0].getWidth()
height = self.images_dict[0].getHeight()
def valid_pos(pos):
return pos >= 0 and pos < self.puzzle.level()
x = (event.getX() - self.canvas.initial_x) / width
y = (event.getY() - self.canvas.initial_y) / height
if not valid_pos(x) or not valid_pos(y):
return
pos = Point(x, y)
if self.pos1 != None: #then is second click
if self.pos1.equals(pos):
self.pos1 = None
else:
self.play_event(self.pos1.y, self.pos1.x, pos.y, pos.x)
self.pos1 = None
else:
self.pos1 = pos
self.canvas.set_selected(self.pos1)
self.canvas.repaint()
def draw(self):
try:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
except:
pass
self.images_dict = dict()
self.canvas = Canvas(self.images_dict, None)
self.canvas.addMouseListener(self)
self.frame = JFrame("SimplePyzzle", visible = 1)
self.frame.setMinimumSize(Dimension(300, 300))
self.frame.setLocationRelativeTo(None)
self.generate_button = JButton("Generate Puzzle")
self.bottom_panel = JPanel()
self.combo_box_list = [9, 16, 25, 36, 49]
self.combo_box = JComboBox(self.combo_box_list)
self.frame.contentPane.add(self.canvas, BorderLayout.CENTER)
self.frame.contentPane.add(self.bottom_panel, BorderLayout.SOUTH)
self.bottom_panel.add(self.generate_button, BorderLayout.EAST)
self.bottom_panel.add(self.combo_box, BorderLayout.WEST)
self.generate_button.actionPerformed = self.generate_board
self.frame.setSize(500, 500)
self.frame.defaultCloseOperation = JFrame.EXIT_ON_CLOSE;
self.frame.pack()
def generate_board(self, event):
chooser = JFileChooser()
status = chooser.showOpenDialog(self.frame)
if status != JFileChooser.APPROVE_OPTION:
return
imageFile = chooser.getSelectedFile()
self.puzzle = SimplePyzzle(float(int(self.combo_box.getSelectedItem())))
self.draw_board()
self.load_images(imageFile, self.puzzle.level())
self.canvas.set_puzzle(self.puzzle)
width = self.images_dict[0].getWidth()
height = self.images_dict[0].getHeight()
size = Dimension(width * self.puzzle.level(), height * self.puzzle.level())
self.frame.setPreferredSize(size)
self.frame.setSize(size)
def show_error(self, error):
JOptionPane.showMessageDialog(self.frame, \
error, \
"Error!", \
JOptionPane.ERROR_MESSAGE)
def load_images(self, file, length):
#.........这里部分代码省略.........