logo
down
shadow

Set transparent background on JList


Set transparent background on JList

By : user2172555
Date : October 23 2020, 08:10 AM
wish help you to fix your issue I don't think that you want to do this sort of change within the cell renderer since that is responsible for drawing the list cells, which are not opaque by default, and not the JList itself.
Instead why not simply give your JList a transparent background color after creating it?
code :
 list.setBackground(new Color(0, 0, 0, 0));
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class JListTest {


    private static void createAndShowGui() {
        final JFrame frame = new JFrame("JList Test");
        final JPanel panel = new JPanel();

        String[] listData = {"One", "Two", "Three", "Four", "Five", "Six"};
        final JList<String> list = new JList<>(listData);
        // list.setOpaque(false);
        list.setBackground(new Color(0, 0, 0, 0));
        list.addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                panel.repaint();
            }
        });

        panel.add(list);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(panel);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> createAndShowGui());
    }
}


Share : facebook icon twitter icon
How to make a movie with transparent background in a flash with transparent background

How to make a movie with transparent background in a flash with transparent background


By : Ra Odan
Date : March 29 2020, 07:55 AM
will help you I'm not sure what you're asking but it looks like the lady on the linked site is just a alpha channel flv (very much like this.) That's accomplished in the encoding process for the video and not in actionscript...are you looking for a programmatic way to do that?
Transparent JList in JScrollPane

Transparent JList in JScrollPane


By : Park Jinho
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I am currently trying to make a JList opaque that is placed in a JScrollPane. I tried to set everything to setOpaque(false), but it still doesn't work. , You don't make the panel (NavigationView) itself transparent
code :
public void initialize() {
    setOpaque(false);
    this.pane = new JScrollPane();
    this.list = new JList();
}
uploading png images with transparent background using php and keeping the background transparent

uploading png images with transparent background using php and keeping the background transparent


By : BsCpE
Date : March 29 2020, 07:55 AM
around this issue I have a php page which takes a user image and uploads it to my webserver.
code :
<?php
$path = "../userfiles/orig/";
$userpath="../".$_REQUEST['userpath']."/";

function getExtension($str) {
  $i = strrpos($str,".");
  if (!$i) { return ""; }
  $l = strlen($str) - $i;
  $ext = substr($str,$i+1,$l);
  return $ext;
}

$valid_formats = array("jpg", "png", "gif", "bmp","jpeg","PNG","JPG","JPEG","GIF","BMP");

if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
  $name = $_FILES['photoimg']['name'];
  $size = $_FILES['photoimg']['size'];

  if(strlen($name)){
    $ext = getExtension($name);

    if(in_array($ext,$valid_formats)){

      if($size<(2048*2048)){
        $time1=time();
        $actual_image_name =$time1."_".str_replace(" ", "_", $name);
        $tmp = $_FILES['photoimg']['tmp_name'];

        if(move_uploaded_file($tmp, $path.$actual_image_name)){
          $image=$actual_image_name;
          /*--------resize image-----------*/
          $size = 320; // the imageheight
          $filedir = '../userfiles/orig/'; // the directory for the original image
          $thumbdir = $userpath; // the directory for the resized image
          $prefix = $time1.'_'; // the prefix to be added to the original name
          $maxfile = '20000000';
          $mode = '0666';
          $userfile_name =str_replace(" ", "", $_FILES['photoimg']['name']);
          $userfile_tmp = str_replace(" ", "", $_FILES['photoimg']['tmp_name']);
          $userfile_size =$_FILES['photoimg']['size'];
          $userfile_type = $_FILES['photoimg']['type'];

          if (isset($_FILES['photoimg']['name'])){
            $prod_img = $filedir.$actual_image_name;
            $prod_img_thumb = $thumbdir.$prefix.$userfile_name;
            move_uploaded_file($userfile_tmp, $prod_img);
            chmod ($prod_img, octdec($mode));
            $sizes = getimagesize($prod_img);
            $aspect_ratio = $sizes[1]/$sizes[0];

            if ($sizes[1] <= $size){
              $new_width = $sizes[0];
              $new_height = $sizes[1];
            }else{
              $new_height = $size;
              $new_width = abs($new_height/$aspect_ratio);
            }
            $destimg=ImageCreateTrueColor($new_width,$new_height)
            or die('Problem In Creating image');

            switch($ext){
              case "jpg":
              case "jpeg":
              case "JPG":
              case "JPEG":
                $srcimg=ImageCreateFromJPEG($prod_img)or die('Problem In opening Source Image');
                break;
              case "PNG":
              case "png":
                $srcimg = imageCreateFromPng($prod_img)or die('Problem In opening Source Image');
                imagealphablending($destimg, false);
                $colorTransparent = imagecolorallocatealpha($destimg, 0, 0, 0, 0x7fff0000);
                imagefill($destimg, 0, 0, $colorTransparent);
                imagesavealpha($destimg, true);

                break;
              case "BMP":
              case "bmp":
                $srcimg = imageCreateFromBmp($prod_img)or die('Problem In opening Source Image');
                break;
              case "GIF":
              case "gif":
                $srcimg = imageCreateFromGif($prod_img)or die('Problem In opening Source Image');
                break;
              default:
                $srcimg=ImageCreateFromJPEG($prod_img)or die('Problem In opening Source Image');
            }

            if(function_exists('imagecopyresampled')){
              imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,imagesX($srcimg),imagesY($srcimg))
              or die('Problem In resizing');
            }else{
              Imagecopyresized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,imagesX($srcimg),imagesY($srcimg))
              or die('Problem In resizing');
            }



            // Saving an image
            switch(strtolower($ext)){
              case "jpg":
              case "jpeg":
                ImageJPEG($destimg,$prod_img_thumb,90) or die('Problem In saving');
                break;

              case "png":
                imagepng($destimg,$prod_img_thumb) or die('Problem In saving');
                break;

              case "bmp":
                imagewbmp($destimg, $prod_img_thumb)or die('Problem In saving');
                break;

              case "gif":
                imagegif($destimg,$prod_img_thumb) or die('Problem In saving');
                break;

              default:
                // if image format is unknown, and you whant save it as jpeg, maybe you should change file extension
                imagejpeg($destimg,$prod_img_thumb,90) or die('Problem In saving');
            }



          }
          unlink($prod_img);
          echo "<img src='".$prod_img_thumb."'>";
        }else{
          echo "Fail upload folder with read access.";
        }
      }else{
        echo "Image file size max 3 MB";
      }

    }else{
      echo "Invalid file format..";
    }
  }else{
    echo "Please select image..!";
  }

  exit;
}
?>
CSS:: Second layer of solid non transparent background on top of transparent background is not working?

CSS:: Second layer of solid non transparent background on top of transparent background is not working?


By : user3228041
Date : March 29 2020, 07:55 AM
it fixes the issue It is happening because of the opacaity given in the parent div.
Check this fiddle.
code :
body{
    background:url('http://moreimg.com/wp-content/uploads/2015/02/iPhone-Wallpaper-HD-010-640x600.jpg');
    /* z-index:0; */
}


#heziGangina{
    background: rgba(255, 255, 255, 0.4);
width: 100%;
display: block;
height: 300px;
}

#GanginaHezi{
   width: 100px;
height: 100px;
margin: 10px auto;
background: url('http://images.all-free-download.com/images/graphicmedium/plain_white_background_211387.jpg');
background-size: 100px;
}
Transparent JList in JScrollPane all in one class

Transparent JList in JScrollPane all in one class


By : Hari
Date : March 29 2020, 07:55 AM
To fix this issue You need to make the JList, JScrollPane AND the JScrollPane's JViewport all transparent, for example...
code :
list.setOpaque(false);
JScrollPane sp = new JScrollPane(list);
sp.setOpaque(false);
sp.getViewport().setOpaque(false);
public class TransparentListCellRenderer extends DefaultListCellRenderer {

    @Override
    public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        setOpaque(isSelected);
        return this;
    }

}
package javaapplication1.pkg295;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class Test {

    public static void main(String[] args) {
        new Test();
    }

    public Test() {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                    ex.printStackTrace();
                }

                JFrame frame = new JFrame("Testing");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setContentPane(new TestPane());

                DefaultListModel model = new DefaultListModel();
                model.addElement("Apple");
                model.addElement("Banana");
                model.addElement("Pear");
                model.addElement("Peach");
                model.addElement("Grap");
                JList list = new JList(model);
                list.setCellRenderer(new TransparentListCellRenderer());
                list.setOpaque(false);
                JScrollPane sp = new JScrollPane(list);
                sp.setOpaque(false);
                sp.getViewport().setOpaque(false);

                frame.add(sp);

                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }
        });
    }

    public class TransparentListCellRenderer extends DefaultListCellRenderer {

        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            setForeground(Color.WHITE);
            setOpaque(isSelected);
            return this;
        }

    }

    public class TestPane extends JPanel {

        private BufferedImage bgImg;

        public TestPane() {
            setLayout(new BorderLayout());
            try {
                bgImg = ImageIO.read(new File("C:\\Users\\shane\\Dropbox\\MegaTokyo\\Aqua\\200x200\\aria_manga_wallpaper-5541.jpg"));
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }

        @Override
        public Dimension getPreferredSize() {
            return bgImg == null ? new Dimension(200, 200) : new Dimension(bgImg.getWidth(), bgImg.getHeight());
        }

        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            if (bgImg != null) {
                Graphics2D g2d = (Graphics2D) g.create();
                int x = (getWidth() - bgImg.getWidth()) / 2;
                int y = (getHeight() - bgImg.getHeight()) / 2;
                g2d.drawImage(bgImg, x, y, this);
                g2d.dispose();
            }
        }

    }

}
Related Posts Related Posts :
  • SpringBoot : No matching bean found exception
  • Implementing the Clonable interface, but don't have to override the clone() method
  • how can i get this code to choose a random word once from each array to print a sentence?
  • Static class to get connections from connection pool
  • Unable to start Chrome browser with user profile in Selenium
  • How to pass a object to be created as a parameter for a method in Java?
  • How to retry with hystrix
  • Loading key to KeyStore fails on Android Oreo
  • Spring+Velocity unsuccessful attempts to save object
  • Private constructor in Kotlin
  • Jetty:run fails with NoSuchMethodError with Spring 5
  • Cannot upload my Web Applicartion in Jboss7 EAP7 EAP
  • How to load a certificate from "Credential storage"?
  • Call Genexus procedure stub in Java environment
  • JavaFX clipping produces a 'lottery scratch ticket'-Effect
  • Using DateTimeFormatter on january first cause an invalid year value
  • Get all the output from Watson conversation using java
  • Java unable to open main class and jar file
  • How to override @override method from activity into another class
  • Adding Runtime VM parameters to intellij for Java 9
  • Java IBM MQ Client connected but not getting messages from queue
  • Questions of Tomcat SSL configuration
  • Stale JNLP files for <extension> (since Java 9?)
  • Properly set (system) properties in JUnit 5
  • Spring MVC Model within POST Method is empty
  • VSTS buildagent: Java 9
  • java.lang.NumberFormatException: For input string: "id" for Hibernate
  • Query id return type
  • Pass variable in API url in java .
  • Reading semicolon delimited csv
  • Get the workspace root
  • Native mmap error
  • hashmap and multiple txt files java
  • Kotlin: Access nested enum class from java
  • Google RateLimiter not Working for counter
  • Spring Boot Application Hanging When Running on Command Line
  • large amount of if else refactor
  • Unable to add xmlunit as dependancy in my pom
  • Scanner input needed twice, when only wanted once
  • How to interpret and translate kotlin code to java?
  • Firebase authentication: signInWithEmailAndPassword method dont respond at all
  • How Remove Recycler Separator/divider programmatically or using xml property
  • Not Able to Save Data Hibernate
  • Toolbar addView not working
  • Freeing memory wrapped with NewDirectByteBuffer
  • Synchronization with implicitwait() do not work, why?
  • Wrapper around Java primitive types
  • ClassNotFoundException: spark.Request when running from command line
  • Exception in Hibernate Configuration
  • How can I validate XML embedded in JSON using Citrus framework?
  • How is the String value passed to the updateText() method?
  • Memory efficient replace functions
  • Upload Photo with onActivityResult, but without Fullscreen capturing
  • Docker: Java 8 installation failing on Ubuntu
  • Java Netbeans Calculator performing wrong calculation
  • Nifi: Threads in nifi
  • While loop Int return inside the method completely dead
  • Checking if a user's entry is an integer using try catch statements
  • Forcing a subclass to provide an initialization method
  • calling a fuction and variables from another class in java
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org