public BooleanPMListCellRenderer() { cb.setHorizontalAlignment(SwingConstants.CENTER); cb.setBorderPainted(false); cb.setOpaque(false); this.setLayout(new BorderLayout()); this.add(this.cb, BorderLayout.CENTER); }
/** Configures a checkbox with the properties of tree cell renderes. */ private static JCheckBox configureCheckBox(JCheckBox checkBox) { checkBox.setHorizontalAlignment(JCheckBox.LEFT); checkBox.setFont(UIManager.getFont("Tree.font")); checkBox.setBorderPainted(false); checkBox.setFocusPainted(false); checkBox.setFocusable(false); checkBox.setOpaque(false); return checkBox; }
public void setJCheckbox(JCheckBox jcb) { jcb.setOpaque(false); jcb.setBorder(null); jcb.setBorderPainted(false); jcb.setMargin(new Insets(0, 0, 0, 0)); jcb.setContentAreaFilled(false); jcb.setFocusable(false); jcb.setFont(new Font("ËÎÌå", 0, 12)); jcb.addMouseListener(new ButtonListener()); }
public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JCheckBox checkbox = (JCheckBox) value; if (!UIUtil.isUnderNimbusLookAndFeel()) { checkbox.setBackground(getBackground(isSelected, checkbox)); checkbox.setForeground(getForeground(isSelected, checkbox)); } checkbox.setEnabled(isEnabled()); checkbox.setFont(getFont(checkbox)); checkbox.setFocusPainted(false); checkbox.setBorderPainted(true); checkbox.setBorder(isSelected ? mySelectedBorder : myBorder); adjustRendering(checkbox, isSelected, cellHasFocus); return checkbox; }
public ValueRenderer(Color colors[]) { super(colors); buttonIconRenderer = new JButton(); buttonIconRenderer.setBorderPainted(false); buttonIconRenderer.setContentAreaFilled(false); buttonIconRenderer.setText("(for AbstractButtons only)"); radioIconRenderer = new JRadioButton(); radioIconRenderer.setBorderPainted(false); radioIconRenderer.setText("for JRadioButtons only)"); checkboxIconRenderer = new JCheckBox(); checkboxIconRenderer.setBorderPainted(false); checkboxIconRenderer.setText("for JCheckBoxes only)"); menuItemIconRenderer = new JMenuItem(); menuItemIconRenderer.setBorderPainted(false); menuItemIconRenderer.setText("(for JMenuItems only)"); }
public Component getListCellRendererComponent( JList<? extends JCheckBox> list, JCheckBox value, int index, boolean isSelected, boolean cellHasFocus) { JCheckBox checkbox = value; // Drawing checkbox, change the appearance here checkbox.setBackground(isSelected ? getSelectionBackground() : getBackground()); checkbox.setForeground(isSelected ? getSelectionForeground() : getForeground()); checkbox.setEnabled(isEnabled()); checkbox.setFont(getFont()); checkbox.setFocusPainted(false); checkbox.setBorderPainted(true); checkbox.setBorder( isSelected ? UIManager.getBorder("List.focusCellHighlightBorder") : noFocusBorder); return checkbox; }
public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (containerBox == null) { containerBox = Box.createHorizontalBox(); checkBox = new JCheckBox(); checkBox.setEnabled(isEnabled()); checkBox.setFont(getFont()); checkBox.setFocusPainted(false); checkBox.setBorderPainted(true); checkBox.setBorder( isSelected ? UIManager.getBorder("List.focusCellHighlightBorder") : noFocusBorder); containerBox.add(checkBox); } checkBox.setBackground(isSelected ? getSelectionBackground() : getBackground()); checkBox.setForeground(isSelected ? getSelectionForeground() : getForeground()); if (value != null) { ListItem item = (ListItem) value; checkBox.setText(item.dataItem.toString()); checkBox.setSelected(item.selected); } return containerBox; }
public CommonPanel(JFrame ownerFrame, IFileSelector fileSelectionPanel) { // try { // FileHandler fh = new FileHandler("log.txt"); // Logger.getLogger(CommonPanel.class.getName()).addHandler(fh); // }catch(IOException ex) { // Logger.getLogger(CommonPanel.class.getName()).log(Level.SEVERE, null, ex); // }catch(SecurityException ex) { // Logger.getLogger(CommonPanel.class.getName()).log(Level.SEVERE, null, ex); // } this.ownerFrame = ownerFrame; this.fileSelectionPanel = fileSelectionPanel; this.fontSizeTF = new JTextField(4); fontSizeTF.setToolTipText("Enter the font size, e.g. 12, 10.5, 22.7"); fontSizeTF.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (!fontSizeSpecRB.isSelected()) fontSizeSpecRB.setSelected(true); } }); fontSizeTF.addMouseListener( new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { super.mousePressed(e); if (!fontSizeSpecRB.isSelected()) fontSizeSpecRB.setSelected(true); System.out.println("fontSizeTF mousePressed"); } @Override public void mouseExited(MouseEvent e) { MouseEvent event = new MouseEvent( fontSizeSpecRB, e.getID(), e.getWhen(), e.getModifiers(), 1, 1, 1, e.isPopupTrigger(), e.getButton()); fontSizeSpecRB.dispatchEvent(event); } @Override public void mouseEntered(MouseEvent e) { MouseEvent event = new MouseEvent( fontSizeSpecRB, e.getID(), e.getWhen(), e.getModifiers(), 1, 1, 1, e.isPopupTrigger(), e.getButton()); fontSizeSpecRB.dispatchEvent(event); } }); String fontSizeRBToolTip = "<html>When this option is selected it enforces that" + "<br> the entered font size is used when creating the output file."; this.fontSizeSpecRB = new JRadioButton("Use the font size "); fontSizeSpecRB.setOpaque(false); fontSizeSpecRB.setToolTipText(fontSizeRBToolTip); JPanel fontSizeSpecPanel = new JPanel(); fontSizeSpecPanel.setToolTipText(fontSizeRBToolTip); // pass events to radiobutton fontSizeSpecPanel.addMouseListener( new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { MouseEvent event = new MouseEvent( fontSizeSpecRB, e.getID(), e.getWhen(), e.getModifiers(), 1, 1, 1, e.isPopupTrigger(), e.getButton()); fontSizeSpecRB.dispatchEvent(event); } @Override public void mouseReleased(MouseEvent e) { MouseEvent event = new MouseEvent( fontSizeSpecRB, e.getID(), e.getWhen(), e.getModifiers(), 1, 1, e.getClickCount(), e.isPopupTrigger(), e.getButton()); fontSizeSpecRB.dispatchEvent(event); } @Override public void mouseExited(MouseEvent e) { MouseEvent event = new MouseEvent( fontSizeSpecRB, e.getID(), e.getWhen(), e.getModifiers(), 1, 1, e.getClickCount(), e.isPopupTrigger(), e.getButton()); fontSizeSpecRB.dispatchEvent(event); } @Override public void mouseEntered(MouseEvent e) { MouseEvent event = new MouseEvent( fontSizeSpecRB, e.getID(), e.getWhen(), e.getModifiers(), 1, 1, e.getClickCount(), e.isPopupTrigger(), e.getButton()); fontSizeSpecRB.dispatchEvent(event); } }); fontSizeSpecPanel.add(fontSizeSpecRB); fontSizeSpecPanel.add(fontSizeTF); fontSizeSpecPanel.setBorder(BorderFactory.createEtchedBorder()); fontSizeSpecPanel.setOpaque(false); this.fitTextToWidthRB = new JRadioButton("Fit text to page width "); fitTextToWidthRB.setBorder(BorderFactory.createEtchedBorder()); fitTextToWidthRB.setBorderPainted(true); fitTextToWidthRB.setOpaque(false); fitTextToWidthRB.setToolTipText( "<html>Don't care about the font size, but make sure" + "<br> the width of input file content will fit into " + "<br>a whole width of a 'pdf' page."); ButtonGroup fontBG = new ButtonGroup(); fontBG.add(fontSizeSpecRB); fontBG.add(fitTextToWidthRB); fitTextToWidthRB.setSelected(true); double p = TableLayout.PREFERRED; TableLayout fontSelectPL = new TableLayout(new double[] {.5, p, p, p, .5}, new double[] {.5, p, .5}); JPanel fontSelectP = new JPanel(fontSelectPL); fontSelectP.setOpaque(false); fontSelectP.add(fontSizeSpecPanel, "1,1,L,C"); fontSelectP.add(new JLabel(" or "), "2,1,C,C"); fontSelectP.add(fitTextToWidthRB, "3,1,R,F"); String[] fonts = { BaseFont.COURIER, BaseFont.HELVETICA, BaseFont.SYMBOL, BaseFont.TIMES_ROMAN, BaseFont.ZAPFDINGBATS }; // , "fonts/lucon.ttf"}; // load font files from the fonts folder String fontFolder = "fonts"; String[] fontFileNames = new String[0]; // Logger.getLogger(CommonPanel.class.getName()).log(Level.INFO, // "ownerFrame must be instanceof Txt2PDFConverterIN is it?=" // +(ownerFrame instanceof Txt2PDFConverterIN) // +"; ownerFrame.getClass().getName()="+ownerFrame.getClass().getName()); if (ownerFrame instanceof Txt2PDFConverterIN) try { fontFileNames = getResourceListing(this.getClass(), fontFolder + "/"); } catch (Exception ex) { // ignore, it could happen when fonts folder doesn't exist, it does // happen when debugging since the folder doesn't exist. // But the folder always is packed in the compact(IN) version of the program. } else { fontFileNames = new File(fontFolder).list(); } // Logger.getLogger(CommonPanel.class.getName()).log(Level.INFO, // "fontFileNames=" + Arrays.toString(fontFileNames)); int initialFontsSize = fonts.length; if (fontFileNames.length > 0) { int newFontsSize = initialFontsSize + fontFileNames.length; fonts = Arrays.copyOf(fonts, newFontsSize); for (int i = initialFontsSize; i < newFontsSize; i++) fonts[i] = fontFolder + "/" + fontFileNames[i - initialFontsSize]; } this.fontCB = new JComboBox(fonts); fontCB.setBorder(BorderFactory.createEtchedBorder()); fontCB.setToolTipText("Select the font to use for output."); String[] encodings = {BaseFont.CP1252, BaseFont.CP1250, BaseFont.CP1257, BaseFont.MACROMAN}; this.encodingCB = new JComboBox(encodings); encodingCB.setBorder(BorderFactory.createEtchedBorder()); encodingCB.setToolTipText("Select encoding used by the input file."); this.portraitRB = new JRadioButton("Portrait "); portraitRB.setBorder(BorderFactory.createEtchedBorder()); portraitRB.setBorderPainted(true); portraitRB.setOpaque(false); portraitRB.setToolTipText("The output file will have pages in portrait orientation."); this.landscapeRB = new JRadioButton("Landscape "); landscapeRB.setBorder(BorderFactory.createEtchedBorder()); landscapeRB.setBorderPainted(true); landscapeRB.setOpaque(false); landscapeRB.setToolTipText("The output file will have pages in landscape orientation."); ButtonGroup pageOrientBG = new ButtonGroup(); pageOrientBG.add(portraitRB); pageOrientBG.add(landscapeRB); portraitRB.setSelected(true); // panel with page orientation settings TableLayout pageOrientPL = new TableLayout(new double[] {5, p, p, p, 5}, new double[] {TableLayout.FILL}); JPanel pageOrientP = new JPanel(pageOrientPL); pageOrientP.setOpaque(false); pageOrientP.add(portraitRB, "1,0,L,F"); pageOrientP.add(new JLabel(" or "), "2,0,C,C"); pageOrientP.add(landscapeRB, "3,0,R,F"); pageOrientP.setBorder(BorderFactory.createEtchedBorder()); TableLayout encodeOrientPL = new TableLayout( new double[] {10, p, 5, p, TableLayout.FILL, p, 10}, new double[] {.5, p, .5}); JPanel fontEncodeOrientP = new JPanel(encodeOrientPL); fontEncodeOrientP.setOpaque(false); fontEncodeOrientP.add(fontCB, "1,1,L,F"); fontEncodeOrientP.add(encodingCB, "3,1,L,F"); fontEncodeOrientP.add(pageOrientP, "5,1,R,F"); this.overwriteOutputFileChB = new JCheckBox("Overwrite output file "); overwriteOutputFileChB.setToolTipText( "When selected it will overwrite the output file if it exists."); overwriteOutputFileChB.setBorder(BorderFactory.createEtchedBorder()); overwriteOutputFileChB.setBorderPainted(true); overwriteOutputFileChB.setOpaque(false); int bW = 80; int bH = 30; this.convertB = new JButton(copnvertAction); convertB.setPreferredSize(new Dimension(bW, bH)); convertB.setToolTipText("Convert the input 'txt' file applying all the selected settings."); this.exitB = new JButton(exitAction); exitB.setPreferredSize(new Dimension(bW, bH)); exitB.setToolTipText("Exit the program."); TableLayout buttonPL = new TableLayout(new double[] {.25, p, .5, p, .25}, new double[] {5, p, 5}); JPanel buttonP = new JPanel(buttonPL); buttonP.setOpaque(false); buttonP.add(convertB, "1,1,C,C"); buttonP.add(exitB, "3,1,C,C"); JLabel infoL = new JLabel("<html><p>  Select conversion settings.</p>"); TableLayout layout = new TableLayout( new double[] {.5, p, .5}, new double[] {.5, p, 5, p, 5, p, 5, p, 10, p, .5}); setLayout(layout); add(infoL, "1,1,L,C"); add(fontSelectP, "1,3,F,C"); add(fontEncodeOrientP, "1,5,F,C"); add(overwriteOutputFileChB, "1,7,C,F"); add(buttonP, "1,9,F,C"); }
private void showSettingsMenu() { JCheckBox snd = new JCheckBox("Музыка"); snd.setSize(310, 75); snd.setSelected(Commons.PLAY_MUSIC); snd.setLocation(Commons.WIDTH / 2 - 310 / 2, 230); snd.setForeground(Color.GREEN); snd.setFont(new Font("arial", 0, 40)); snd.setBorderPainted(false); snd.setFocusPainted(false); snd.setContentAreaFilled(false); snd.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Commons.PLAY_MUSIC = snd.isSelected(); } }); String[] items = {"Легкая", "Средняя", "Сложная", "Невозможная"}; JComboBox<String> list = new JComboBox<String>(items); switch (Commons.DIFFICULTY) { case Commons.EASY_DIFFICULTY_CLOUDS_CNT: list.setSelectedIndex(0); break; case Commons.MEDIUM_DIFFICULTY_CLOUDS_CNT: list.setSelectedIndex(1); break; case Commons.HARD_DIFFICULTY_CLOUDS_CNT: list.setSelectedIndex(2); break; case Commons.IMPOSSIBLE_DIFFICULTY_CLOUDS_CNT: list.setSelectedIndex(3); break; } list.setSize(310, 40); list.setLocation(Commons.WIDTH / 2 - 310 / 2, 430); list.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int st = list.getSelectedIndex(); switch (st) { case 0: Commons.DIFFICULTY = Commons.EASY_DIFFICULTY_CLOUDS_CNT; break; case 1: Commons.DIFFICULTY = Commons.MEDIUM_DIFFICULTY_CLOUDS_CNT; break; case 2: Commons.DIFFICULTY = Commons.HARD_DIFFICULTY_CLOUDS_CNT; break; case 3: Commons.DIFFICULTY = Commons.IMPOSSIBLE_DIFFICULTY_CLOUDS_CNT; break; } } }); add(list); JLabel diff_lbl = new JLabel(); diff_lbl.setText("Сложность:"); diff_lbl.setFont(new Font("serif", 0, 40)); diff_lbl.setForeground(Color.GREEN); diff_lbl.setSize(300, 75); diff_lbl.setLocation(list.getLocation().x, list.getLocation().y - 100); add(diff_lbl); JButton back = new JButton("Назад"); back.setSize(190, 75); back.setLocation(Commons.WIDTH / 2 - 190 / 2, Commons.HEIGHT - 150); back.setForeground(Color.GREEN); back.setBorderPainted(false); back.setFocusPainted(false); back.setContentAreaFilled(false); back.setFont(new Font("serif", 0, 40)); back.addActionListener(ev -> showMainMenu()); add(back); add(snd); }